❌❌❌❌❌❌❌❌
DeprecatioNoticePleasecosiderusigtourmalieistead
I'lltrytokeepthislibrarycompatiblewiththefutureversiosofCrystal,buttourmalieisawelldesigedadmaitaiedlibrarywhichissuperiorieverywaywhilesharigthesamebasics,thusIdo'tseeayvalueiimplemetigthesameimprovemetsadfragmetigthecommuity
Bugfixesarestillwelcomed
❌❌❌❌❌❌❌❌
TelegramBotTelegramBotAPI(3.2)wrapperforCrystal
Curretfeaturesapimethodsadtypes:
basicmessagetypesstickersiliemodepaymetsgamesgettigupdates:
logpolligwebhooksadditioalfeatures:
white&blacklistscommadhadlerUsageCreateyourbotbyiheritigfromTelegramBot::Bot.
CommadsDefiewhichcommadsyourbothadlesviathecmdmethoditheCmdHadlermodule.Forexample,respodworldto/helloadperformsimplecalculatiowith/add:
require"telegram_bot"classMyBot<TelegramBot::BoticludeTelegramBot::CmdHadlerdefiitializesuper("MyBot",TOKEN)cmd"hello"do|msg|replymsg,"world!"ed#/add57=>12cmd"add"do|msg,params|replymsg,"#{params[0].to_i+params[1].to_i}"edededmy_bot=MyBot.ewmy_bot.polligLoggigMyBot::Log.level=:debugMyBot::Log.backed=::Log::IOBacked.ewmy_bot=MyBot.ewmy_bot.polligCustomhadlersOverrideayofthefollowighadlemethodstohadleTelegramupdates,beitmessages,iliequeries,choseilieresultsorcallbackqueries:
defhadle(message:Message)defhadle(ilie_query:IlieQuery)defhadle(chose_ilie_result:ChoseIlieResult)defhadle(callback_query:CallbackQuery)defhadle_edited(message:Message)defhadle_chael_post(message:Message)defhadle_edited_chael_post(message:Message)Forexample,toechoallmessagessettothebot:
classEchoBot<TelegramBot::Botdefhadle(message:Message)iftext=message.textreplymessage,textedededEchoBot.ew.polligOrtoasweriliequerieswithalistofarticles:
classIlieBot<TelegramBot::Botdefhadle(ilie_query:TelegramBot::IlieQuery)results=Array(TelegramBot::IlieQueryResult).ewcotet=IputTextMessageCotet.ew"Articledetails"results<<TelegramBot::IlieQueryResultArticle.ew("article/1","Myfirstarticle",cotet)aswer_ilie_query(ilie_query.id,results)ededIlieBot.ew.polligRemembertoeableiliemodeiBotFathertosupportiliequeries.
WebhooksAlltheexamplesaboveusethegetUpdatesmethod,costatlypolligTelegramforewupdates,byivokigthepolligmethodothebot.
AotheroptioistousethesetWebhookmethodtotellTelegramwheretoPOSTayupdatesforyourbot.NotethatyoumustuseHTTPSithisedpoitforTelegramtowork,adyoucauseaself-sigedcertificate,whichyoucaprovideaspartofthesetWebhookmethod:
#Certificatehasthecotetsofthecertificate,otthepathtoitbot.set_webhook(url,certificate)AfterivokigsetWebhook,haveyourbotstartaHTTPSserverwiththeservecommad:
bot.serve("0.0.0.0",443,"path/to/ssl/certificate","path/to/ssl/key")IfyouruyourbotbehidaproxythatperformsSSLoffloadig(ietheproxypresetsthecertificatetoTelegram,adtheforwardstherequesttoyourappusigplaiHTTP),youmayskipthelasttwoparameters,adthebotwilllisteforHTTPrequestsisteadofHTTPS.
Wheruigyourbotiservemode,thebotwillfavourexecutigaymethodsbysedigaresposeaspartoftheTelegramrequest,ratherthaexecutigaewrequest.
White/blacklistsHoweverit'sotpartoftheAPIyoucasetblackorwhitelistsithebot'scostructortofilteryourusersbyuserame.
whitelist:ifuserisotpresetothelist(ordoes'thaveuserame)themessagewo'tbehadled
blacklist:ifuserispresetothelistthemessagewo'tbehadled
IstallatioAddthistoyourapplicatio'sshard.yml:
depedecies:telegram_bot:github:hagyas/telegram_botCotributigCotributigisverywelcomed!
Forkit(https://github.com/hagyas/TelegramBot/fork)Createyourfeaturebrach(gitcheckout-bmy-ew-feature)Commityourchages(gitcommit-am'Addsomefeature')Pushtothebrach(gitpushorigimy-ew-feature)CreateaewPullRequestCotributorshagyasKrisztiáÁdám-creator,maitaier






评论