wayanjimmy / telegram-bot

Telegram Bot boilerplate in Elixir

Home Page:https://t.me/ElixirDemoBot

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

telegram-bot

An Elixir app to create your own Telegram bot.

๐Ÿ‘‰ Development

A couple of helper scripts available under scripts/ to ease development on your local machine.

Working on the bot locally:

  1. Register your Bot using Telegram's @BotFather and get the bot token.

  2. Start ngrok on http port 8080 by running ngrok http 8080. This will act as reverse proxy to your bot's port since we're using webhook method to handle the message.

  3. Create .env file and fill it with environment variables that we'll pass to the app:

    BOT_HOST=<your-ngrok-subdomain-here>.ngrok.io
    BOT_TOKEN=<your-bot-token-here>
    
  4. Start the bot with the helper script: ./script/dev. It will start an iex shell (iex -S mix)

  5. Start developing.

You'll want to update the lib/bot.ex to suit your need (handle messages and make replies).

๐Ÿ‘‰ Deployment

It's up to you on how to and where you want to deploy your bot. My favorite method is Docker image and deploy it anywhere that support Docker deployment.

Here how I deploy to Fly.io.

Pre-requisites:

  • Make sure you have an account at Fly.io
  • Make sure you have fly CLI installed
  • Make sure you're logged-in using fly auth login

Deploy steps:

  1. Run fly launch and follow required steps (you only need to do this once and fly.toml file will generated - see fly.toml.example)

  2. Set bot environment variable as secrets:

    fly secrets set BOT_HOST=<your-fly-io-appname>.fly.dev
    fly secrets set BOT_TOKEN=<your-bot-token>
    
  3. Run fly deploy to proceed with deployment.

If everything works as expected we'll have our bot up and running on fly.io and you can start sending it messages (commands).

๐Ÿ‘‰ Demo bot

Open this link t.me/ElixirDemoBot and send it /ping message and it will reply with pong! or send any message (unknown commands) and see the replies.

About

Telegram Bot boilerplate in Elixir

https://t.me/ElixirDemoBot

License:MIT License


Languages

Language:Elixir 79.1%Language:Dockerfile 19.0%Language:Shell 1.8%