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

outdated

A Dart library interfacing with the latest Telegram Bot API.

example/main.dart

import 'dart:io' show Platform;
// import 'dart:io' as io;

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

void main() {
  final envVars = Platform.environment;

  var telegram = Telegram(envVars['BOT_TOKEN']);
  var teledart = TeleDart(telegram, Event());

  // In case you decided to use webhook.
  // var webhook = Webhook(telegram, envVars['HOST_URL'], envVars['BOT_TOKEN'])
  //   ..certificate = io.File(envVars['CERT_PATH'])
  //   ..privateKey = io.File(envVars['KEY_PATH'])
  //   ..port = int.parse(envVars['BOT_PORT']);
  // var teledart = TeleDart(telegram, Event(), fetcher: webhook);

  // TeleDart uses longpoll by default if no update fetcher is specified.
  teledart.start().then((me) => print('${me.username} is initialised'));

  // You can listen to messages like this
  teledart.onMessage(entityType: 'bot_command', keyword: 'start').listen(
      (message) =>
          teledart.telegram.sendMessage(message.chat.id, 'Hello TeleDart!'));

  // Or using short cuts
  teledart
      .onCommand('short')
      .listen(((message) => teledart.replyMessage(message, 'This works too!')));

  // You can also utilise regular expressions
  teledart.onCommand(RegExp('hello', caseSensitive: false)).listen(
      (message) => teledart.telegram.sendMessage(message.chat.id, 'hi!'));

  // You can even filter streams with stream processing methods
  // See: https://www.dartlang.org/tutorials/language/streams#methods-that-modify-a-stream
  teledart
      .onMessage(keyword: 'dart')
      .where((message) => message.text.contains('telegram'))
      .listen((message) => teledart.replyPhoto(
          message,
          //  io.File('example/dash_paper_plane.png'),
          'https://raw.githubusercontent.com/DinoLeung/TeleDart/master/example/dash_paper_plane.png',
          caption: 'This is how Dash found the paper plane'));

  // Sick of boilerplates? Reply messages like below, nice and tidy
  // Short hands also available for answer query methods
  teledart
      .onMessage(keyword: 'Fight for freedom')
      .listen((message) => message.reply('Stand with Hong Kong'));

  // Inline mode.
  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')
      ]));
}
279
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