telegram_bot开源项目

我要开发同款
匿名用户2021年11月08日
197阅读

技术信息

开源地址
https://github.com/esl/elarm
授权协议
MIT License

作品详情

❌❌❌❌❌❌❌❌

DeprecatioNotice

Pleasecosiderusigtourmalieistead

I'lltrytokeepthislibrarycompatiblewiththefutureversiosofCrystal,buttourmalieisawelldesigedadmaitaiedlibrarywhichissuperiorieverywaywhilesharigthesamebasics,thusIdo'tseeayvalueiimplemetigthesameimprovemetsadfragmetigthecommuity

Bugfixesarestillwelcomed

❌❌❌❌❌❌❌❌

TelegramBot

TelegramBotAPI(3.2)wrapperforCrystal

Curretfeatures

apimethodsadtypes:

basicmessagetypesstickersiliemodepaymetsgames

gettigupdates:

logpolligwebhooks

additioalfeatures:

white&blacklistscommadhadlerUsage

CreateyourbotbyiheritigfromTelegramBot::Bot.

Commads

DefiewhichcommadsyourbothadlesviathecmdmethoditheCmdHadlermodule.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.polligCustomhadlers

OverrideayofthefollowighadlemethodstohadleTelegramupdates,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.pollig

Ortoasweriliequerieswithalistofarticles:

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.pollig

RemembertoeableiliemodeiBotFathertosupportiliequeries.

Webhooks

AlltheexamplesaboveusethegetUpdatesmethod,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/blacklists

Howeverit'sotpartoftheAPIyoucasetblackorwhitelistsithebot'scostructortofilteryourusersbyuserame.

whitelist:ifuserisotpresetothelist(ordoes'thaveuserame)themessagewo'tbehadled

blacklist:ifuserispresetothelistthemessagewo'tbehadled

Istallatio

Addthistoyourapplicatio'sshard.yml:

depedecies:telegram_bot:github:hagyas/telegram_botCotributig

Cotributigisverywelcomed!

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

功能介绍

❌❌❌❌❌❌❌❌ Deprecation Notice Please consider using tourmaline instead I'll try to keep this librar...

声明:本文仅代表作者观点,不代表本站立场。如果侵犯到您的合法权益,请联系我们删除侵权资源!如果遇到资源链接失效,请您通过评论或工单的方式通知管理员。未经允许,不得转载,本站所有资源文章禁止商业使用运营!
下载安装【程序员客栈】APP
实时对接需求、及时收发消息、丰富的开放项目需求、随时随地查看项目状态

评论