All Projects → hangyas → telegram_bot

hangyas / telegram_bot

Licence: MIT license
(deprecated) see https://github.com/protoncr/tourmaline instead

Programming Languages

crystal
512 projects

Projects that are alternatives of or similar to telegram bot

qbittorrent-bot
Telegram bot to mange your qBittorrent torrents
Stars: ✭ 91 (+26.39%)
Mutual labels:  telegram-bot
telegram-stepfunctions-bot
Serverless Telegram bot made on 4 AWS Lambda chained by AWS Step Functions. All of this written on Serverless Framework using plugins.
Stars: ✭ 26 (-63.89%)
Mutual labels:  telegram-bot
Telegram.Bot.Extensions.Polling
Provides ITelegramBotClient extensions for polling updates
Stars: ✭ 35 (-51.39%)
Mutual labels:  telegram-bot
Telegram-PHP-App
App base for Telegram bots
Stars: ✭ 14 (-80.56%)
Mutual labels:  telegram-bot
tgcf
The ultimate tool to automate custom telegram message forwarding. Live-syncer, Auto-poster, backup-bot, cloner, chat-forwarder, duplicator, ... Call it whatever you like! tgcf can fulfill your custom needs.
Stars: ✭ 378 (+425%)
Mutual labels:  telegram-bot
Feedback-bot
In Short This is An Personalized Livegram Bot Made Using Python.. Follow Me @HeimanPictures & Star This Repo
Stars: ✭ 23 (-68.06%)
Mutual labels:  telegram-bot
kiririn
A serverless Telegram bot.
Stars: ✭ 27 (-62.5%)
Mutual labels:  telegram-bot
telegram client
library for help you make userbot or bot telegram and support tdlib telegram database and only support nodejs dart and google-apps-script
Stars: ✭ 38 (-47.22%)
Mutual labels:  telegram-bot
greed
A customizable, multilanguage Telegram shop bot with Telegram Payments support
Stars: ✭ 268 (+272.22%)
Mutual labels:  telegram-bot
telegram-keyboard
Simple and powerful reply and inline keyboard builder for Telegram Bots
Stars: ✭ 70 (-2.78%)
Mutual labels:  telegram-bot
agala
Full featured messaging bot framework.
Stars: ✭ 70 (-2.78%)
Mutual labels:  telegram-bot
kirpich
Пацан-бот
Stars: ✭ 77 (+6.94%)
Mutual labels:  telegram-bot
tgcli
Telegram Terminal Application
Stars: ✭ 39 (-45.83%)
Mutual labels:  telegram-bot
tgto
Telegram to RSS bot.
Stars: ✭ 20 (-72.22%)
Mutual labels:  telegram-bot
async py bot
dark0ghost.github.io/async_py_bot/
Stars: ✭ 23 (-68.06%)
Mutual labels:  telegram-bot
genshin task-resin-expedition alert
完全摸了,之后若有需要,请使用下面链接的这个仓库~
Stars: ✭ 91 (+26.39%)
Mutual labels:  telegram-bot
FileConvertBot
Telegram Bot that converts some file types to native photo, audio or video Telegram messages.
Stars: ✭ 32 (-55.56%)
Mutual labels:  telegram-bot
TamilVcMusic
A telegram bot for which is help to play songs in vc 🥰 give 🌟 and fork this repo before use 😏
Stars: ✭ 126 (+75%)
Mutual labels:  telegram-bot
GitHub-Webhook-Bot
It is a Simple Telegram Bot, which will listen to GitHub Webhook and inform via Telegram
Stars: ✭ 33 (-54.17%)
Mutual labels:  telegram-bot
mirror-leech-telegram-bot
Aria/qBittorrent Telegram mirror/leech bot
Stars: ✭ 1,289 (+1690.28%)
Mutual labels:  telegram-bot

Deprecation Notice

Please consider using tourmaline instead

I'll try to keep this library compatible with the future versions of Crystal, but tourmaline is a well designed and maintained library which is superior in every way while sharing the same basics, thus I don't see any value in implementing the same improvements and fragmenting the community

Bug fixes are still welcomed

TelegramBot

Telegram Bot API (3.2) wrapper for Crystal

Current features

api methods and types:

  • basic message types
  • stickers
  • inline mode
  • payments
  • games

getting updates:

  • long polling
  • webhooks

additional features:

  • white & black lists
  • command handler

Usage

Create your bot by inheriting from TelegramBot::Bot.

Commands

Define which commands your bot handles via the cmd method in the CmdHandler module. For example, respond world to /hello and perform simple calculation with /add:

require "telegram_bot"

class MyBot < TelegramBot::Bot
  include TelegramBot::CmdHandler

  def initialize
    super("MyBot", TOKEN)

    cmd "hello" do |msg|
      reply msg, "world!"
    end

    # /add 5 7 => 12
    cmd "add" do |msg, params|
      reply msg, "#{params[0].to_i + params[1].to_i}"
    end
  end
end

my_bot = MyBot.new
my_bot.polling

Logging

MyBot::Log.level = :debug
MyBot::Log.backend = ::Log::IOBackend.new

my_bot = MyBot.new
my_bot.polling

Custom handlers

Override any of the following handle methods to handle Telegram updates, be it messages, inline queries, chosen inline results or callback queries:

def handle(message : Message)

def handle(inline_query : InlineQuery)

def handle(chosen_inline_result : ChosenInlineResult)

def handle(callback_query : CallbackQuery)

def handle_edited(message : Message)

def handle_channel_post(message : Message)

def handle_edited_channel_post(message : Message)

For example, to echo all messages sent to the bot:

class EchoBot < TelegramBot::Bot
  def handle(message : Message)
    if text = message.text
      reply message, text
    end
  end
end

EchoBot.new.polling

Or to answer inline queries with a list of articles:

class InlineBot < TelegramBot::Bot
  def handle(inline_query : TelegramBot::InlineQuery)
    results = Array(TelegramBot::InlineQueryResult).new

    content = InputTextMessageContent.new "Article details"
    results << TelegramBot::InlineQueryResultArticle.new("article/1", "My first article", content)

    answer_inline_query(inline_query.id, results)
  end
end

InlineBot.new.polling

Remember to enable inline mode in BotFather to support inline queries.

Webhooks

All the examples above use the getUpdates method, constantly polling Telegram for new updates, by invoking the polling method on the bot.

Another option is to use the setWebhook method to tell Telegram where to POST any updates for your bot. Note that you must use HTTPS in this endpoint for Telegram to work, and you can use a self-signed certificate, which you can provide as part of the setWebhook method:

# Certificate has the contents of the certificate, not the path to it
bot.set_webhook(url, certificate)

After invoking setWebhook, have your bot start an HTTPS server with the serve command:

bot.serve("0.0.0.0", 443, "path/to/ssl/certificate", "path/to/ssl/key")

If you run your bot behind a proxy that performs SSL offloading (ie the proxy presents the certificate to Telegram, and then forwards the request to your app using plain HTTP), you may skip the last two parameters, and the bot will listen for HTTP requests instead of HTTPS.

When running your bot in serve mode, the bot will favour executing any methods by sending a response as part of the Telegram request, rather than executing a new request.

White/blacklists

However it's not part of the API you can set black or white lists in the bot's constructor to filter your users by username.

whitelist: if user is not present on the list (or doesn't have username) the message won't be handled

blacklist: if user is present on the list the message won't be handled

Installation

Add this to your application's shard.yml:

dependencies:
  telegram_bot:
    github: hangyas/telegram_bot

Contributing

Contributing is very welcomed!

  1. Fork it ( https://github.com/hangyas/TelegramBot/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Contributors

  • hangyas Krisztián Ádám - creator, maintainer
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].