Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Dockerfile for building a docker image for a type script web project.
# pull base image
FROM node:12.2.0-alpine

# set working directory
WORKDIR /usr/src/app

# add `/usr/src/app/node_modules/.bin` to $PATH
ENV PATH /usr/src/app/node_modules/.bin:$PATH

# install and cache dependencies
COPY ./package.json /usr/src/app/package.json
COPY ./main.ts /usr/src/app/main.ts
COPY ./tsconfig.json /usr/src/app/tsconfig.json
COPY ./yarn.lock /usr/src/app/yarn.lock
RUN yarn
CMD ["yarn", "start"]
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ cp .env.example .env
```bash
yarn start # or `npm start`
```
4. Configure "Request URL" with `http(s)://domain:port` and add "Message received [v2.0] - im.message.receive_v1" event in "Event Subscription" - "Lark Developer App Panel".
4. Configure "Request URL" with `http(s)://domain:port/event` and add "Message received [v2.0] - im.message.receive_v1" event in "Event Subscription" - "Lark Developer App Panel".
5. Go to "Permissions & Scopes" and add all permissions that "im.message.receive_v1" requires and the following permissions.
- im:message
- im:message:send_as_bot
Expand All @@ -36,6 +36,7 @@ yarn start # or `npm start`

## Robot Command
```text
/help help message
/reset # Reset user's session context
/img <prompt> # Generate an image with the given prompt
```
Expand Down
11 changes: 11 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# docker-compose.yam file for running a web service. the image is build from the Dockerfile and the image name is larkgpt.
version: '3'
services:
larkgpt:
build: .
image: larkgpt
container_name: larkgpt
ports:
- "3000:3000"
env_file:
- .env
11 changes: 10 additions & 1 deletion main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ const INIT_COMMAND = env.INIT_COMMAND ||
'The following is a conversation with an AI assistant. The assistant is helpful, creative, clever, and very friendly.'
const TEXT_MODEL = env.TEXT_MODEL || 'text-davinci-003'
const IMAGE_SIZE = env.IMAGE_SIZE || '1024x1024'
const HELP_MESSAGE = env.HELP_MESSAGE || `/help help message
/reset # Reset user's session context
/img <prompt> # Generate an image with the given prompt`

async function reply (
messageID: string, content: string) {
Expand Down Expand Up @@ -219,6 +222,8 @@ const eventDispatcher = new lark.EventDispatcher({
if (content === '/reset') {
cache.del(`session:${userID}`)
return await reply(messageID, '[COMMAND] Session reset successfully.')
} else if (content === '/help') {
return await reply(messageID, HELP_MESSAGE)
} else if (content.match(/^\/img \S+/)) {
const imageKey = await createImage(userID,
content.replace(/^\/img /, ''))
Expand Down Expand Up @@ -260,5 +265,9 @@ const eventDispatcher = new lark.EventDispatcher({
server.on('request',
lark.adaptDefault('/event', eventDispatcher, { autoChallenge: true }))

server.listen(env.PORT)
server.listen({
host: env.LISTEN_IP,
port: env.PORT
})

console.info(`[${env.LARK_APP_NAME}] Now listening on port ${env.PORT}`)