A bot works with OpenAI GPT models to provide insights for your info flows.

  • By Neko Ayaka
  • Last update: Aug 14, 2023
  • Comments: 5

insights-bot

A bot works with OpenAI GPT models to provide insights for your info flows.

简体中文


Supported IMs

  • Telegram
  • Slack
  • Discord

Usage

Commands

Insights Bot ships with a set of commands, you can use /help to get a list of available commands when talking to the bot in Telegram. You can also use /cancel to cancel any ongoing actions with the bot.

Summarize webpages

Command: /smr

Arguments: URL, Replied message with only URL

Usage:

/smr https://www.example.com
/smr [Reply to a message with only URL]

By sending /smr command with a URL or replying to a message that only contains a URL, the bot will try to summarize the webpage and return the result.

Configure chat history recapturing

Warning
This command is not available in Slack/Discord integration currently.

Command: /configure_recap

Arguments: None

/configure_recap

By sending /configure_recap command, the bot will send you a message with options you can interact with. Click the buttons to choose the settings you want to configure.

Summarize chat histories or Recap

Warning
This command is not available in Slack/Discord integration currently.

Command: /recap

Arguments: None

/recap

By sending /recap command, the bot will try to summarize the chat histories and return the result you choose later.

Subscribe to chat histories recap for a group

Warning
This command is not available in Slack/Discord integration currently.

Command: /subscribe_recap

Arguments: None

/subscribe_recap

By sending /subscribe_recap command, the bot will start to capture the messages from the group you subscribed and then send a copy of the recap message to you through private chat when it is available.

Unsubscribe to chat histories recap for a group

Warning
This command is not available in Slack/Discord integration currently.

Command: /unsubscribe_recap

Arguments: None

/unsubscribe_recap

By sending /unsubscribe_recap command, the bot will no longer send the copy of the recap message for the group you subscribe.

Summarize forwarded messages in private chat

Warning
This command is not available in Slack/Discord integration currently.

Commands: /recap_forwarded_start, /recap_forwarded

Arguments: None

/recap_forwarded_start
[Forward a message]
/recap_forwarded

By sending /recap_forwarded_start command, the bot will start to capture the forwarded messages you send later in private chat and try to summarize them when you send /recap_forwarded command afterwards.

Deployment

Run with binary

You will have to clone this repository and then build the binary by yourself.

git clone https://github.com/nekomeowww/insights-bot
go build -a -o "build/insights-bot" "github.com/nekomeowww/insights-bot/cmd/insights-bot"

Then copy the .env.example file to build directory and rename it to .env, and then fill in the environment variables.

cd build
cp ../.env.example .env
vim .env
# assign executable permission to the binary
$ chmod +x ./insights-bot
# run the binary
$ ./insights-bot

Run with docker

docker run -it --rm -e TELEGRAM_BOT_TOKEN=<Telegram Bot API Token> -e OPENAI_API_SECRET=<OpenAI API Secret Key> -e DB_CONNECTION_STR="<PostgresSQL connection URL>" insights-bot ghcr.io/nekomeowww/insights-bot:latest

Run with docker-compose

Create your .env by making a copy of the contents from .env.example file. The .env file should be placed at the root of the project directory next to your docker-compose.yml file.

Replace your OpenAI token and other environment variables in .env, and then run:

docker-compose --profile hub up -d

If you prefer run docker image from local codes, then run:

docker-compose --profile local up -d --build

Build on your own

Build with go

go build -a -o "release/insights-bot" "github.com/nekomeowww/insights-bot/cmd/insights-bot"

Build with Docker

docker buildx build --platform linux/arm64,linux/amd64 -t <tag> -f Dockerfile .

Ports we use

Port Description
6060 pprof Debug server
7069 Health check server
7070 Slack App/Bot webhook server
7071 Telegram Bot webhook server
7072 Discord Bot webhook server

Configurations

Environment variables

Name Required Default Description
TIMEZONE_SHIFT_SECONDS false 0 Timezone shift in seconds used for auto generating recap messages for groups, default is 0.
TELEGRAM_BOT_TOKEN true Telegram Bot API token, you can create one and obtain the token through @BotFather
TELEGRAM_BOT_WEBHOOK_URL false Telegram Bot webhook URL and port, you can use https://ngrok.com/ or Cloudflare tunnel to expose your local server to the internet.
TELEGRAM_BOT_WEBHOOK_PORT false 7071 Telegram Bot Webhook server port, default is 7071
OPENAI_API_SECRET true OpenAI API Secret Key that looks like sk-************************************************, you can obtain one by signing in to OpenAI platform and create one at http://platform.openai.com/account/api-keys.
OPENAI_API_HOST false https://api.openai.com OpenAI API Host, you can specify one if you have a relay or reversed proxy configured. Such as https://openai.example.workers.dev
OPENAI_API_MODEL_NAME false gpt-3.5-turbo OpenAI API model name, default is gpt-3.5-turbo, you can specify one if you want to use another model. Such as gpt-4
DB_CONNECTION_STR true PostgreSQL database URL. Such as postgres://postgres:postgres@localhost:5432/postgres. You could also suffix with ?search_path=<schema name> if you want to specify a schema
SLACK_CLIENT_ID false Slack app client id, you can create a slack app and get it, see: tutorial
SLACK_CLIENT_SECRET false Slack app client secret, you can create a slack app and get it, see: tutorial
SLACK_WEBHOOK_PORT false 7070 Port for Slack Bot/App Webhook server, default is 7070
DISCORD_BOT_TOKEN false Discord bot token, you can create a discord app and get it, see: Get started document
DISCORD_BOT_PUBLIC_KEY false Discord bot public key, you can create a discord app and get it, see: Get started document, required if DISCORD_BOT_TOKEN provided.
DISCORD_BOT_WEBHOOK_PORT false 7072 Port for Discord Bot Webhook server, default is 7702
REDIS_HOST true localhost Redis host connects to, default is localhost
REDIS_PORT true 6379 Redis port, default is 6379
REDIS_TLS_ENABLED false false Redis TLS enabled, default is false
REDIS_USERNAME false Redis username.
REDIS_PASSWORD false Redis password.
REDIS_DB false 0 Redis database, default is 0
REDIS_CLIENT_CACHE_ENABLED false false Redis client cache enabled, default is false, read more about client cache at https://redis.io/docs/manual/client-side-caching/ and https://github.com/redis/rueidis#client-side-caching for more details.
LOG_FILE_PATH false <insights-bot_executable>/logs/insights-bot.log Log file path, you can specify one if you want to specify a path to store logs when executed and ran with binary. The default path is /var/log/insights-bot/insights-bot.log in Docker volume, you can override the defaults -e LOG_FILE_PATH=<path> when executing docker run command or modify and prepend a new LOG_FILE_PATH the docker-compose.yml file.
LOG_LEVEL false info Log level, available values are debug, info, warn, error

Acknowledgements

  • Project logo was generated by Midjourney
  • OpenAI for providing the GPT series models

Download

insights-bot.zip

Comments(5)

  • 1

    fix(docker-compose): specify username and database in postgres healthcheck

    This commit fixes the error of role "root" does not exist when running healthcheck for postgres service in docker-compose. 需要在pg的healthcheck中指定用户,不然docker-compose会不停报2023-07-13 17:19:16.813 UTC [34] FATAL: role "root" does not exist的错误

  • 2

    fix(heatlhcheck): add curl to Dockerfile, supports to set password for Redis from envs

    This commit fixes the error of /bin/sh: 1: curl: not found when running healthcheck for insights_bot service in docker-compose. 需要在insights-bot容器内装上curl,否则 这里的 healthcheck会报/bin/sh: 1: curl: not found

  • 3

    feat request: support to configure recap and autorecap to control where to send recaps

    Brief

    Scenario 1

    In group 1:

    Creator: /enable_recap Bot: ask for recap mode, whether publicly or privately Creator: Select -> if privately is selected, check if user is creator or not, if not a creator, reject the request Bot: deletes /enable_recap from creator, deletes selections from Bot

    Scenario 2

    In group 1:

    Creator: /configure_recap Bot: ask for recap mode, whether publicly or privately Creator: Select -> if privately is selected, check if user is creator or not, if not a creator, reject the request Bot: deletes /configure_recap from creator, deletes selections from Bot

    Scenario 3

    In group 1:

    User: /recap Bot: -> Try to send a message to state out the process is started. -> if it fails to do so, send /start and reply to user (ask user to enable the bot or unblock the bot) -> if it succeeded, proceed to summarize the chat histories from targeted group and send to user Bot: deletes /recap from user,deletes /start from Bot

    Scenario 4

    In group 1:

    User: /subscribe_recap Bot: -> Try to send a message to state out whether the action has succeeded. -> if it fails to do so, send /start and reply to user (ask user to enable the bot or unblock the bot) -> if it succeeded, proceed to subscribe auto recaps for user <after time interval to send auto recaps> Bot: look for subscribed users and try to summarize the chat histories from targeted group and send to user, if it fails to do so, ignore.

    by @KexyBiscuit

  • 4

    feat: introduce health check handler

    By using alexliesenfeld/health, implement health checkers for:

    • Slack Bot Webhook handler Gin engine
    • Telegram Bot Puller / Webhook handler Gin engine
    • Autorecap cron
    • Pprof server
  • 5

    feat: i18n support

    • [ ] i18n help messages
    • [ ] i18n error message handling
    • [ ] i18n reply message handling
    • [ ] i18n prompt with multi-language support
      • [x] #70
    • [ ] configurable i18n options (through inline keyboard or whatever)