AsyncTelegramBotAPIClientimplementin@Nim-Lang
NotesFromversion1.0.0,procslikesnewMessage,newPhoto,..aregone,usesendMessage,sendDocumentinstead.Ifyoustillprefertheold/uglywaytosendstuffs,justimporttelebot/compatforbackwardcompatible
Installation$nimbleinstalltelebotUsageechobotimporttelebot,asyncdispatch,logging,optionsvarL=newConsoleLogger(fmtStr="$levelname,[$time]")addHandler(L)constAPI_KEY=slurp("secret.key")procupdateHandler(b:Telebot,u:Update):Future[bool]{.async.}=ifnotu.message.isSome:#returntruewillmakebotstopprocessothercallbacksreturntruevarresponse=u.message.getifresponse.text.isSome:lettext=response.text.getdiscardawaitb.sendMessage(response.chat.id,text,parseMode="markdown",disableNotification=true,replyToMessageId=response.messageId)letbot=newTeleBot(API_KEY)bot.onUpdate(updateHandler)bot.poll(timeout=300)sendlocalphotoimporttelebot,asyncdispatch,options,loggingconstAPI_KEY=slurp("secret.key")procupdateHandler(bot:TeleBot,update:Update):Future[bool]{.async.}=discardawaitbot.sendPhoto(response.chat.id,"file:///path/to/photo.jpg")letbot=newTeleBot(API_KEY)bot.onUpdate(updateHandler)bot.poll(timeout=300)FormoreinformationpleaserefertoofficialTelegramBotAPIpage
评论