Skip to content

Latest commit

 

History

History
82 lines (72 loc) · 1.82 KB

README.md

File metadata and controls

82 lines (72 loc) · 1.82 KB

Botex telegram

Telegram module for :bot_ex

How to start:

  #mix.exs
  def deps do
    [
      {:botex_telegram, "~> 0.0.1"}
    ]
  end

 config :bot_ex,
   ....
    bots: [:telegram],
    middlware: [
      telegram: [
        BotexTelegram.Middleware.NadiaMessageTransformer,
        BotexTelegram.Middleware.Auth,
        BotexTelegram.Middleware.TextInput,
        BotEx.Middleware.MessageLogger,
        BotexTelegram.Middleware.MessageLogger
      ]
    ],
    handlers: [
      telegram: [
        #tupples with {module, buffering time}
        {BotexTelegram.Handlers.Start, 500},
        {BotexTelegram.Handlers.Menu, 500}
      ]
    ]

  #the interval for getting updates from telegram api
  config :bot_ex, update_interval: 1000
#application.ex
def start(_type, _args) do
  children = [
    BotexTelegram.Updaters.Telegram,
    BotexTelegram.Services.Menu.Api
  ]

  opts = [strategy: :one_for_one, name: BotTest.Supervisor]
  Supervisor.start_link(children, opts)
end

Example menu.exs

%{
   "main_menu" => %BotEx.Models.Menu{
     #can be defined as functions
     # buttons: fn() -> [] end
     buttons: [
       [
         %BotEx.Models.Button{
           action: "some",
           data: "data",
           module: BotexTelegram.Handlers.Start.get_cmd_name(),
           text: "This is button"
         }
       ]
     ]
   }
 }

Routing

Rouring create from defined handlers. Each handler have function get_cmd_name/0 that return command name for this handler. When user call /start command, router find module for handle by answer get_cmd_name/0 value.

Optionaly you can create file routes.exs and redefine or add aliases for your commands

Example routes.exs

%{
  telegram:
    %{"s" => BotexTelegram.Handlers.Start}
}