All Projects → nexor → telega

nexor / telega

Licence: MIT license
Telegram Bot API implementation

Programming Languages

d
599 projects
Dockerfile
14818 projects
Makefile
30231 projects

Projects that are alternatives of or similar to telega

gotgbot
Autogenerated Go wrapper for the telegram API. Inspired by the python-telegram-bot library.
Stars: ✭ 178 (+747.62%)
Mutual labels:  telegram-bot-api
react-telegram
(WIP) A React custom renderer for the Telegram Bot API.
Stars: ✭ 14 (-33.33%)
Mutual labels:  telegram-bot-api
todoist bot
@Todoist_bot for Telegram (UNofficial)
Stars: ✭ 35 (+66.67%)
Mutual labels:  telegram-bot-api
nestjs-telegraf
🤖 Powerful Nest module for easy and fast creation Telegram bots
Stars: ✭ 300 (+1328.57%)
Mutual labels:  telegram-bot-api
wikibot
A 🤖 which provides features from Wikipedia like summary, title searches, location API etc.
Stars: ✭ 25 (+19.05%)
Mutual labels:  telegram-bot-api
finch
A Golang Telegram Bot framework
Stars: ✭ 23 (+9.52%)
Mutual labels:  telegram-bot-api
theimagebot
Blog.TheOstrich.Eu.Org
Stars: ✭ 15 (-28.57%)
Mutual labels:  telegram-bot-api
teleflask
A python telegram bot framework based on flask and pytgbot
Stars: ✭ 43 (+104.76%)
Mutual labels:  telegram-bot-api
telegram bot
Script ini digunakan untuk mengontrol MikroTik Anda hanya dengan menggunakan sosial media Telegram.
Stars: ✭ 27 (+28.57%)
Mutual labels:  telegram-bot-api
telegram-bot-sdk
🤖 Telegram Bot API PHP SDK. Create Telegram Bots with PHP Easily! [WIP - DO NOT USE IN PRODUCTION YET]
Stars: ✭ 64 (+204.76%)
Mutual labels:  telegram-bot-api
ZEGBot
Build your Telegram Bot with Swift! (works on macOS / Ubuntu)
Stars: ✭ 52 (+147.62%)
Mutual labels:  telegram-bot-api
telegram-log
Send a Telegram message when your scripts fire an exception or when they finish their execution.
Stars: ✭ 16 (-23.81%)
Mutual labels:  telegram-bot-api
Nutgram
The Telegram bot framework that doesn't drive you nuts.
Stars: ✭ 206 (+880.95%)
Mutual labels:  telegram-bot-api
python-telegram-bot-calendar
Python inline calendar for Telegram bots
Stars: ✭ 71 (+238.1%)
Mutual labels:  telegram-bot-api
telegram
Golang Telegram Bot API
Stars: ✭ 13 (-38.1%)
Mutual labels:  telegram-bot-api
wptelegram
Integrate your WordPress site perfectly with Telegram with full control.
Stars: ✭ 31 (+47.62%)
Mutual labels:  telegram-bot-api
telresender
A Telegram bot, which resend your message to another account
Stars: ✭ 22 (+4.76%)
Mutual labels:  telegram-bot-api
tdlight-java
Complete Bot and Userbot Telegram library based on TDLib
Stars: ✭ 128 (+509.52%)
Mutual labels:  telegram-bot-api
github client
Open source bot telegram menggunakan bahasa code dart
Stars: ✭ 24 (+14.29%)
Mutual labels:  telegram-bot-api
telegram-standup-bot
Very simple telegram bot for submitting daily standups
Stars: ✭ 23 (+9.52%)
Mutual labels:  telegram-bot-api

Telega

Telegram bot API implementation.

Dub version Build Status

Run examples

To run examples from examples/ dir you need to create a bot and put it as BOT_TOKEN variable in .env file at the root of this repository.

$ cat .env
BOT_TOKEN=123456789:BotTokenHere

Now you can run examples using make command

$ make run-example-echobot
$ make run-example-keyboard
$ make run-example-pollbot

Quickstart

Simple echo bot example

import vibe.core.core : runApplication, runTask;
import vibe.core.log : setLogLevel, logInfo, LogLevel;
import std.process : environment;
import std.exception : enforce;

int main(string[] args)
{
    string botToken = environment.get("BOT_TOKEN");

    if (args.length > 1 && args[1] != null) {
        logInfo("Setting token from first argument");
        botToken = args[1];
    }

    enforce(botToken !is null, "Please provide bot token as a first argument or set BOT_TOKEN env variable");

    setLogLevel(LogLevel.diagnostic);
    runTask(&listenUpdates, botToken);

    return runApplication();
}

void listenUpdates(string token)
{
    import telega.botapi : BotApi;
    import telega.telegram.basic : Update, getUpdates, sendMessage;
    import std.algorithm.iteration : filter, each;
    import std.algorithm.comparison : max;

    int offset;
    auto api = new BotApi(token);

    while (true)
    {
        api.getUpdates(offset)
            .filter!(u => !u.message.text.isNull) // we need all updates with text message
            .each!((Update u) {
                logInfo("Text from %s: %s", u.message.chat.id, u.message.text);
                api.sendMessage(u.message.chat.id, u.message.text);
                offset = max(offset, u.id)+1;
            });
    }
}

Installation

You can add package to your project using dub:

dub add telega

Todo

  • Sending files
  • Inline mode
  • Bot API 4.3 and newer

Help

You can find some examples in the examples dir

API types and methods can be found in telega.telegram.* modules.

Each method is typically implemented using 3 constructs:

  • structure for the method fully describing its signature;
  • a function that accepts a few arguments representing required method arguments
  • a function that accepts a reference to a method struct for calling method with required and optional arguments

For example:

// full method structure
struct SendMessageMethod
{
    mixin TelegramMethod!"/sendMessage";

    ChatId    chat_id;
    string    text;
    Nullable!ParseMode parse_mode;
    Nullable!bool      disable_web_page_preview;
    Nullable!bool      disable_notification;
    Nullable!uint      reply_to_message_id;

    ReplyMarkup reply_markup;
}

// short form - only required args
Message sendMessage(T)(BotApi api, T chatId, string text) if (isTelegramId!T)

// full form - need to build SendTelegramMethod struct first
Message sendMessage(BotApi api, ref SendMessageMethod m)

Some hints

ChatId type is actually long or string

isTelegramId!T template checks T to be some string or number

Support

Issues and PR's are welcome.

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