Simple Telegram bot integration to OpenAI ChatGPT API, written in Go

  • By Valeriy Selitskiy
  • Last update: Aug 10, 2023
  • Comments: 12

Simple Telegram bot integration to OpenAI ChatGPT API


Disclaimer

⚠️ This code represents a working instance of the bot named @net_nebot on Telegram. Other bots may be running the same code, and may be used for malicious purposes. Use at your own risk!

This is not an official OpenAI nor Telegram product. This is a community project.

The code is provided as is, and is not guaranteed to work.


Self-hosting

The easiest way to self-host the bot is to build a Docker image and run it on a server of your choice. The Dockerfile is provided in the repository.

You will need to provide the following arguments to the build command:

docker build -t telegram-chatgpt-bot . \
  --build-arg OPENAI_TOKEN=<required, your_api_token> \
  --build-arg BOT_TOKEN=<required, your_bot_token> \
  --build-arg CHATGPT_VERSION=<optional, 3.5 | 4> 

You can also run the bot locally

docker run -d --restart always --name  telegram-chatgpt-bot telegram-chatgpt-bot

Translations

The bot is currently available in the following languages: English, Russian, Belarusian, Ukrainian. Feel free to contribute translations for other languages! The ChatGPT API itself understands a lot more languages, so go give it a try!

Download

telegram-chatgpt-bot.zip

Comments(12)

  • 1

    build(deps): bump github.com/sashabaranov/go-openai from 1.12.0 to 1.13.0

    Bumps github.com/sashabaranov/go-openai from 1.12.0 to 1.13.0.

    Release notes

    Sourced from github.com/sashabaranov/go-openai's releases.

    v1.13.0

    What's Changed

    New Contributors

    Full Changelog: https://github.com/sashabaranov/go-openai/compare/v1.12.0...v1.13.0

    Commits
    • 619ad71 docs: added instructions for obtaining OpenAI API key to README (#421)
    • 5c7d882 Allow embeddings requests to be tokens or strings (#417)
    • 2042608 docs: remove medatada in PULL_REQUEST_TEMPLATE.md (#423)
    • 177c143 Fix OpenAI error when properties is empty in function call : object schema mi...
    • 1efcf2d fix: move pull request template (#420)
    • 9c99f36 replace deprecated FunctionDefine in chat_test.go (#416)
    • 86d0f48 chore: add a pull request template (#412)
    • 581f70b chore: add an issue template for bug report (#408)
    • a3c0b36 chore: add an issue template for feature request (#410)
    • See full diff in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
  • 2

    build(deps): bump github.com/sashabaranov/go-openai from 1.11.2 to 1.11.3

    Bumps github.com/sashabaranov/go-openai from 1.11.2 to 1.11.3.

    Release notes

    Sourced from github.com/sashabaranov/go-openai's releases.

    v1.11.3

    What's Changed

    New Contributors

    Full Changelog: https://github.com/sashabaranov/go-openai/compare/v1.11.2...v1.11.3

    Commits
    • ffa7abc Update README.md (#399)
    • e19b074 docs: add requires go version in README.md (#397)
    • f22da8a feat: allow more input types to functions, fix tests (#377)
    • e948150 fix: chat stream returns an error response with a 'data: ' prefix (#396)
    • 7203770 feat: added function call info to chat completions (#390)
    • 68f9ef9 split integration test using go build tag (#392)
    • b095938 extract and split integration tests (#389)
    • e49d771 support for parsing error response message fields even if they are arrays (#3...
    • See full diff in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
  • 3

    build(deps): bump github.com/sashabaranov/go-openai from 1.10.1 to 1.11.1

    Bumps github.com/sashabaranov/go-openai from 1.10.1 to 1.11.1.

    Release notes

    Sourced from github.com/sashabaranov/go-openai's releases.

    v1.11.1

    What's Changed

    Full Changelog: https://github.com/sashabaranov/go-openai/compare/v1.11.0...v1.11.1

    v1.11.0

    What's Changed

    New Contributors

    Full Changelog: https://github.com/sashabaranov/go-openai/compare/v1.10.1...v1.11.0

    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
  • 4

    build(deps): bump golang.org/x/sys from 0.8.0 to 0.9.0

    Bumps golang.org/x/sys from 0.8.0 to 0.9.0.

    Commits
    • 55b11dc unix: remove recently introduced debug/elf dependency
    • 5059a07 unix: implement Ptrace{Set,Get}Regs using PTRACE_{GET,SET}REGSET for Linux
    • 304f187 unix: replace use of strcpy in mkerrors.sh
    • 81c8a6c unix: add Getresuid and Getresgid for OpenBSD
    • ff98eae unix: remove absolute path of pwd from mkall.sh
    • b52f544 unix: add Getresuid, Getresgid for linux
    • b5c7a09 unix: update BPF constants with Linux kernel 6.2
    • c8ea6b0 windows: fix EnumProcesses to pass the correct array size
    • 352d833 cpu: add test for IsBigEndian
    • c43fe1e cpu: define IsBigEndian on wasm
    • Additional commits viewable in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
  • 5

    build(deps): bump github.com/sashabaranov/go-openai from 1.9.5 to 1.10.0

    Bumps github.com/sashabaranov/go-openai from 1.9.5 to 1.10.0.

    Release notes

    Sourced from github.com/sashabaranov/go-openai's releases.

    v1.10.0

    What's Changed

    New Contributors

    Full Changelog: https://github.com/sashabaranov/go-openai/compare/v1.9.5...v1.10.0

    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
  • 6

    build(deps): bump github.com/sirupsen/logrus from 1.9.0 to 1.9.1

    Bumps github.com/sirupsen/logrus from 1.9.0 to 1.9.1.

    Commits
    • b30aa27 Merge pull request #1339 from xieyuschen/patch-1
    • 6acd903 Merge pull request #1376 from ozfive/master
    • 105e63f Merge pull request #1 from ashmckenzie/ashmckenzie/fix-writer-scanner
    • c052ba6 Scan text in 64KB chunks
    • e59b167 Merge pull request #1372 from tommyblue/syslog_different_loglevels
    • 766cfec This commit fixes a potential denial of service vulnerability in logrus.Write...
    • 70234da Add instructions to use different log levels for local and syslog
    • a448f82 Merge pull request #1362 from FrancoisWagner/fix-data-race-in-hooks-test-pkg
    • ff07b25 Fix data race in hooks.test package
    • d8787af Use text when shows the logrus output
    • See full diff in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
  • 7

    build(deps): bump github.com/sashabaranov/go-openai from 1.7.0 to 1.8.0

    Bumps github.com/sashabaranov/go-openai from 1.7.0 to 1.8.0.

    Release notes

    Sourced from github.com/sashabaranov/go-openai's releases.

    v1.8.0

    What's Changed

    New Contributors

    Full Changelog: https://github.com/sashabaranov/go-openai/compare/v1.7.0...v1.8.0

    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
  • 8

    build(deps): bump golang.org/x/net from 0.13.0 to 0.14.0

    Bumps golang.org/x/net from 0.13.0 to 0.14.0.

    Commits
    • c8c0290 go.mod: update golang.org/x dependencies
    • 0b21d06 quic: framework for testing blocking operations
    • 4648651 quic: add -vv flag for more verbose tests
    • 60ae793 quic: don't send session tickets
    • a7da556 http2: optimize buffer allocation in transport
    • 167593b quic: create and accept streams
    • See full diff in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
  • 9

    build(deps): bump golang.org/x/sys from 0.10.0 to 0.11.0

    ⚠️ Dependabot is rebasing this PR ⚠️

    Rebasing might not happen immediately, so don't worry if this takes some time.

    Note: if you make any changes to this PR yourself, they will take precedence over the rebase.


    Bumps golang.org/x/sys from 0.10.0 to 0.11.0.

    Commits
    • 104d401 unix: add riscv_hwprobe for riscv64
    • 70f4e40 unix: retry fetching of lists through sysctl if the size changes
    • ad7130c unix: add more block device ioctl numbers
    • c406141 all: fix some typos
    • 25d0004 unix: fix last argument of pselect6 on linux
    • 706fa98 windows: remove repetitive words
    • 3fead03 unix: add Mremap for netbsd
    • See full diff in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
  • 10

    build(deps): bump golang.org/x/net from 0.12.0 to 0.13.0

    Bumps golang.org/x/net from 0.12.0 to 0.13.0.

    Commits
    • 8ffa475 html: only render content literally in the HTML namespace
    • 63fe334 quic: gate and queue synchronization primitives
    • bd8ac9e quic: fill out connection id handling
    • 08001cc quic: debug logging of packets
    • dd0aa33 quic: tls handshake
    • 5e678bb quic: CRYPTO stream handling
    • dd5bc96 internal/quic: deflake TestConnTestConn
    • d0912d4 quic: add pipe type
    • 8db2ead quic: transport parameter encoding and decoding
    • 0adcadf quic: send and receive datagrams
    • Additional commits viewable in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
  • 11

    build(deps): bump github.com/sashabaranov/go-openai from 1.14.0 to 1.14.1

    Bumps github.com/sashabaranov/go-openai from 1.14.0 to 1.14.1.

    Release notes

    Sourced from github.com/sashabaranov/go-openai's releases.

    v1.14.1

    What's Changed

    New Contributors

    Full Changelog: https://github.com/sashabaranov/go-openai/compare/v1.14.0...v1.14.1

    Commits
    • 1153eb2 Add support for azure openai new version API (2023-07-01-preview) (#451)
    • 1876e0c update to json.RawMessage (#441)
    • 0234c1e add example: fine tune (#438)
    • e22a29d Check if the model param is valid for moderations endpoint (#437)
    • 39b2acb ci: set up closing-inactive-issues in GitHub Action (129) (#428)
    • See full diff in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
  • 12

    build(deps): bump github.com/sashabaranov/go-openai from 1.14.1 to 1.14.2

    Bumps github.com/sashabaranov/go-openai from 1.14.1 to 1.14.2.

    Release notes

    Sourced from github.com/sashabaranov/go-openai's releases.

    v1.14.2

    What's Changed

    New Contributors

    Full Changelog: https://github.com/sashabaranov/go-openai/compare/v1.14.1...v1.14.2

    Commits
    • a14bc10 docs: Add Contributing Guidelines (#463)
    • 3456989 Compatible with the 2023-07-01-preview API interface of Azure Openai, when co...
    • 71a2493 docs: add Frequently Asked Questions to README.md (#462)
    • 62dc817 feat: make finish reason nullable in json marshal (#449)
    • See full diff in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot show <dependency name> ignore conditions will show all of the ignore conditions of the specified dependency
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)