TelegramGLib is a bot api for telegram written in Vala
- Inline mode support
- Async request sending
- File uploading
- Handlers support
- Android support
using Telegram;
void main() {
var bot = new Bot() {
token = "YOUR_BOT_TOKEN"
};
// Reply to message with text 'priority'
// This MessageHandler will have more priority because
// It was added before handler which replies on any message
bot.add_handler(new MessageHandler("priority", msg => {
bot.send.begin(new SendMessage() {
chat_id = msg.chat.id,
text = "Handler priority example"
});
}));
// Reply to any message
// Except handlers with same type added before this
bot.add_handler(new MessageHandler(null, msg => {
bot.send.begin(new SendMessage() {
chat_id = msg.chat.id,
text = @"Your message: $(msg.text)"
});
}));
// Send greeting message if user started bot
bot.add_handler(new CommandHandler("start", msg => {
bot.send.begin(new SendMessage() {
chat_id = msg.chat.id,
text = "Welcome!"
});
// Check if chat is private
}, msg => msg.chat.type == Chat.Type.PRIVATE));
bot.start();
}
$ valac --pkg telegram-glib-1.0 main.vala
$ ./main
Python
import gi
gi.require_version('Telegram', '1.0')
from gi.repository import Telegram
class PingBot(Telegram.Bot):
def __init__(self, **kargs):
super().__init__(**kargs)
self.token = 'YOUR_BOT_TOKEN'
def do_on_message(self, message):
if message.text is not None:
msg = Telegram.SendMessage()
msg.chat_id = message.chat.id
msg.text = 'Your message: ' + message.text
self.send(msg)
return True
bot = PingBot()
bot.start()
- TelegramGLib-Examples repository
var request = new SendPhoto();
request.chat_id = update.message.chat.id;
// To upload local file use prefix 'file://'
// File will be uploaded from local folder (/home/paladin/Pictures/upload.jpg)
request.photo = "file:///home/paladin/Pictures/upload.jpg";
send.begin(request);
Installation for Android (Guide)
Download TelegramGLib from AUR
$ yay -S telegram-glib
json-glib-1.0
libsoup-3.0
$ meson setup --prefix=/usr build
$ ninja -C build install
- Webhook support
- Write documentation
- Telegram passport support