Telegram bot plugin system written in Elixir.
Telegram is an instant messaging system which has a nice UI and fast server response.
By using Telegram server infrastructure to build your bot, you have a reliable communication backend system for your application free of charge!
Also, Telegram bot api allow you to send customized keyboard to Telegram UI, which is available for both mobile and web. This is so nice that you do not have to create your own UI.
To ensure you can easily leverage the above things, this is where telebot kicks in.
- Creating a home VPN access (Of course you dont want your home appliance on the internet!)
- Creating your own server to receive commands. e.g. json/http
- Adding application logic to act upon receiving commands. e.g. Turning on air-conditioner
- Creating UI to send the commands.
- Creating a Telegram bot account. (Once only)
- Creating a Telebot handler which act upon receiving commands.
Add the following lines to mix.exs in your project
def application do
[applications: [:telebot]]
end
defp deps do
[{:telebot, git: "git://github.com/ottolin/telebot.git"}]
endThen update dependencies by:
mix deps.get
In order to work with Telegram server, you need an api key. The key can be obtained by sending message to BotFather
After obtaining your key, add the following lines to config.exs:
config :telebot, :api_key,
"Your API Key Right Here"Now you are able to write your own bot by implementing the behaviour Telebot.Handler. To simplify this process, just use Telebot.Handler.Base and override any callback that you are interested in.
In the following example, you can have an echo Telegram bot in just a few lines of code.
defmodule MyEchoBot do
use Telebot.Handler.Base
# overriding the text() callback
def text(from, chat, t), do: Telebot.Api.send_message(chat.id, "Echo: " <> t)
endFinally, add your bot module to config.exs:
config :telebot, :handlers,
[MyEchoBot]Enjoy your bot by running
iex -S mix
By sending messages to your registered bot account, you should now see the reply from bot!