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:
-
Register your Bot using Telegram's
@BotFather
and get the bot token. -
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. -
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>
-
Start the bot with the helper script:
./script/dev
. It will start aniex
shell (iex -S mix
) -
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:
-
Run
fly launch
and follow required steps (you only need to do this once andfly.toml
file will generated - seefly.toml.example
) -
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>
-
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.