teledart 0.2.2 copy "teledart: ^0.2.2" to clipboard
teledart: ^0.2.2 copied to clipboard

outdated

A Dart library interfacing with the latest Telegram Bot API.

TeleDart #

Telegram is a popular secured instant messenger. They have an open bot platform, this package is a Dart implementation of their bot API allowing you to create your own bot easily.

TeleDart

Bot API Version Dart Version License: GPL v3

Creating a Telegram bot #

In order to create a Telegram bot, you need to use @BotFather. Follow the instructions in BotFather, then copy your bot token and you're ready to go.

Usage #

Initializing the bot:

import 'package:teledart/teledart.dart';
import 'package:teledart/telegram.dart';

void main() {
  var telegram = Telegram(BOT_TOKEN); // Replace BOT_TOKEN with the token of your bot
  var event = Event((await telegram.getMe()).username!);
  var teledart = TeleDart(telegram, event);

  teledart.start()

  // ...
}

A simple usage example:

teledart
  ..onMessage(keyword: 'Fight for freedom')
    .listen((message) => message.reply('Stand with Hong Kong'));

Using bot commands:

// Long way
teledart.onMessage(entityType: 'bot_command', keyword: 'start').listen(
    (message) =>
        teledart.telegram.sendMessage(message.chat.id, 'Hello TeleDart!'));

// Short way (recommended)
teledart
    .onCommand('short')
    .listen(((message) => teledart.replyMessage(message, 'This works too!')));

Modifying Stream:

teledart
    .onMessage(keyword: 'dart')
    .where((message) => message.text?.contains('telegram') ?? false)
    .listen((message) => message.replyPhoto(
        //  io.File('example/dash_paper_plane.png'),
        'https://raw.githubusercontent.com/DinoLeung/TeleDart/master/example/dash_paper_plane.png',
        caption: 'This is how the Dart Bird and Telegram are met'));

Inline mode example:

teledart.onInlineQuery().listen((inlineQuery) => inlineQuery.answer([
      InlineQueryResultArticle(
          id: 'ping',
          title: 'ping',
          input_message_content: InputTextMessageContent(
              message_text: '*pong*', parse_mode: 'MarkdownV2')),
      InlineQueryResultArticle(
          id: 'ding',
          title: 'ding',
          input_message_content: InputTextMessageContent(
              message_text: '*_dong_*', parse_mode: 'MarkdownV2')),
    ]));

Bugs and feature requests #

Please file feature requests and bugs at the issue tracker.

277
likes
0
pub points
89%
popularity

Publisher

verified publisherd1n0.xyz

A Dart library interfacing with the latest Telegram Bot API.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

http, json_annotation

More

Packages that depend on teledart