Created
December 3, 2016 19:08
-
-
Save paavohuhtala/099fd3e826b2b37901108881e0ff7430 to your computer and use it in GitHub Desktop.
Telegram echo bot in F# \w Hopac
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open System | |
open Telegram.Bot | |
open Telegram.Bot.Types | |
open Telegram.Bot.Types.Enums | |
open Hopac | |
let token = "nope" | |
let msgBox = Mailbox<Message> () | |
module Bot = | |
let replyToMsg (bot: TelegramBotClient) (msg: Message) x = job { | |
do! Job.awaitUnitTask (bot.SendChatActionAsync(msg.Chat.Id, ChatAction.Typing)) | |
do! timeOutMillis (String.length x * 10 + 100) | |
do! Job.awaitUnitTask (bot.SendTextMessageAsync(msg.Chat.Id, x)) | |
} | |
let serverJob bot = job { | |
let! msg = Mailbox.take msgBox | |
printfn "%s" msg.Text | |
do! Bot.replyToMsg bot msg msg.Text | |
} | |
[<EntryPoint>] | |
let main argv = | |
let bot = Telegram.Bot.TelegramBotClient(token) | |
bot.GetMeAsync().Result |> ignore | |
bot.StartReceiving () | |
bot.OnMessage.Add (fun x -> Mailbox.Now.send msgBox x.Message) | |
Job.foreverServer (serverJob bot) | |
|> start | |
Console.ReadKey (true) | |
|> ignore | |
0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment