diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..836380c --- /dev/null +++ b/Dockerfile @@ -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"] \ No newline at end of file diff --git a/README.md b/README.md index 86b2e04..b474ecf 100644 --- a/README.md +++ b/README.md @@ -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 @@ -36,6 +36,7 @@ yarn start # or `npm start` ## Robot Command ```text +/help help message /reset # Reset user's session context /img # Generate an image with the given prompt ``` diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..65fb26c --- /dev/null +++ b/docker-compose.yml @@ -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 \ No newline at end of file diff --git a/main.ts b/main.ts index f2d6228..0c7351c 100644 --- a/main.ts +++ b/main.ts @@ -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 # Generate an image with the given prompt` async function reply ( messageID: string, content: string) { @@ -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 /, '')) @@ -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}`)