Skip to content
This repository has been archived by the owner on Nov 25, 2020. It is now read-only.

rekyuu-archive/elixir_telegram_bot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

40 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Elixir Telegram Bot

This version is no longer maintained.

Check out Ooyodo for the newer and more sane version.

A elixir app that uses Telegram methods from Nadia to poll for updates and respond to them.

If you don't know much about Telegram bots, I suggest reading the Telegram Bot API docs.

Installation

$ git clone https://github.com/rekyuu/elixir_telegram_bot
$ cd elixir_telegram_bot
$ mix deps.get

You will need to edit config/config.exs and add your bot's username:

config :telegram_bot,
  username: "your_bot_name"

Then you need to create config/secret.exs with the following contents:

use Mix.Config

config :nadia,
  token: "your-telegram-bot-api-key"

Then run your bot using iex -S mix.

Commands

You want to edit lib/telegram_bot/commands.ex. There are a couple of examples in there for you to go off of, but here they are explained:

command "expression" do

"expression" would be the name of the command. IE, /start would appear as command "start" do. This can also be a list of commands that do the same thing, ex: command ["hi", "hello"] do.

match "expression" do

This matches the message exactly. Be sure that your bot has privacy disabled with Botfather to see all user message or this won't work. This can also be parsed with a list of expressions.

reply "text"

Does what it says, replies to the same chat that the message originated from. There are a couple others I've added:

reply_no_preview "text"

reply_photo "/path/to/image.png"

reply_photo_with_caption "/path/to/image.png", "caption text"

Message handling

Each of the above wrappers handle the incoming message as a Nadia struct and is passed as the variable msg. The example given in commands.ex is as follows:

match ["hello", "hi", "hey", "sup"] do
  case msg do
    %{from: %{username: name}}   -> reply "Hi there, @#{name}!"
    %{from: %{first_name: name}} -> reply "Hi there, #{name}!"
  end
end

About

A bot wrapper for Telegram, written in Elixir.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages