telegram_bot.mdx 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. ---
  2. title: "📱 Telegram Bot"
  3. ---
  4. ### 🖼️ Template Setup
  5. - Open the Telegram app and search for the `BotFather` user.
  6. - Start a chat with BotFather and use the `/newbot` command to create a new bot.
  7. - Follow the instructions to choose a name and username for your bot.
  8. - Once the bot is created, BotFather will provide you with a unique token for your bot.
  9. <Tabs>
  10. <Tab title="docker">
  11. ```bash
  12. docker run --name telegram-bot -e OPENAI_API_KEY=sk-xxx -e TELEGRAM_BOT_TOKEN=xxx -p 8000:8000 embedchain/telegram-bot
  13. ```
  14. <Note>
  15. If you wish to use **Docker**, you would need to host your bot on a server.
  16. You can use [ngrok](https://ngrok.com/) to expose your localhost to the
  17. internet and then set the webhook using the ngrok URL.
  18. </Note>
  19. </Tab>
  20. <Tab title="replit">
  21. <Card>
  22. Fork <ins>**[this](https://replit.com/@taranjeetio/EC-Telegram-Bot-Template?v=1#README.md)**</ins> replit template.
  23. </Card>
  24. - Set your `OPENAI_API_KEY` in Secrets.
  25. - Set the unique token as `TELEGRAM_BOT_TOKEN` in Secrets.
  26. </Tab>
  27. </Tabs>
  28. - Click on `Run` in the replit container and a URL will get generated for your bot.
  29. - Now set your webhook by running the following link in your browser:
  30. ```url
  31. https://api.telegram.org/bot<Your_Telegram_Bot_Token>/setWebhook?url=<Replit_Generated_URL>
  32. ```
  33. - When you get a successful response in your browser, your bot is ready to be used.
  34. ### 🚀 Usage Instructions
  35. - Open your bot by searching for it using the bot name or bot username.
  36. - Click on `Start` or type `/start` and follow the on screen instructions.
  37. 🎉 Happy Chatting! 🎉