diff options
author | href <href@random.sh> | 2021-09-02 05:57:21 +0200 |
---|---|---|
committer | href <href@random.sh> | 2021-09-02 06:37:06 +0200 |
commit | fccd0d02849f4a800fe878cb43f239f3d5e28636 (patch) | |
tree | 8bb20091bd3c9e723b25d6e7d85e1dc9e733cb0f /lib/lsg/telegram.ex | |
parent | Revert "preums: remove migration code" (diff) |
telegram: plumb room
Diffstat (limited to 'lib/lsg/telegram.ex')
-rw-r--r-- | lib/lsg/telegram.ex | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/lib/lsg/telegram.ex b/lib/lsg/telegram.ex index d393a2c..e5790da 100644 --- a/lib/lsg/telegram.ex +++ b/lib/lsg/telegram.ex @@ -14,6 +14,10 @@ defmodule LSG.Telegram do end @impl Telegram.ChatBot + def init(chat_id) when chat_id < 0 do + {:ok, state} = LSG.TelegramRoom.init(chat_id) + {:ok, %{room_state: state}} + end def init(chat_id) do Logger.info("Telegram session starting: #{chat_id}") account = IRC.Account.find_meta_account("telegram-id", chat_id) @@ -22,6 +26,11 @@ defmodule LSG.Telegram do end @impl Telegram.ChatBot + def handle_update(update, token, %{room_state: room_state}) do + {:ok, room_state} = LSG.TelegramRoom.handle_update(update, token, room_state) + {:ok, %{room_state: room_state}} + end + def handle_update(%{"message" => m = %{"chat" => %{"type" => "private"}, "text" => text = "/start"<>_}}, _token, state) do text = "*Welcome to beautte!*\n\nQuery the bot on IRC and say \"enable-telegram\" to continue." send_message(m["chat"]["id"], text) @@ -168,6 +177,16 @@ defmodule LSG.Telegram do {:ok, state} end + @impl Telegram.ChatBot + def handle_info(info, %{room_state: room_state}) do + {:ok, room_state} = LSG.TelegramRoom.handle_info(info, room_state) + {:ok, %{room_state: room_state}} + end + + def handle_info(_info, state) do + {:ok, state} + end + defp as_irc_message(id, text, account) do reply_fun = fn(text) -> send_message(id, text) end trigger_text = cond do |