telegrambot 0.1.0

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 17

Telegram Bot

Introduction

Library to implement a Telegram Bot.

Example

var bot = new TelegramBot('<token>');

var updates = pollForUpdates(bot);

await for (var update in updates) {
  if (update.message != null) {
      bot.sendCommand(new SendMessage.plainText(update.message.chat.id,
          "Hello, I'm just a bot. Don't expect too much from me."));
  }
}

Features

  • Poll for incoming messages
  • Sending text messages
    • Plaintext, html, markdown
    • Reply, Forward
    • Keyboards
  • Inline bot
    • Reply with text
    • Reply with GIF
    • Support for InlineKeyboard

Missing Features

  • Webhooks
  • Audio/Video/Files/Photos
  • Chat Management
  • Games
  • Payments
  • Framework
    • Logging
    • Error handling
    • Strong validation

License and contributors

Changelog

0.1.0

  • Initial version.

example/example.dart

// Copyright (c) 2017, TOPdesk. Please see the AUTHORS file for details.
// All rights reserved. Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

import 'dart:async';
import 'dart:io';
import 'package:telegrambot/telegrambot.dart';

Future<dynamic> main(List<String> args) async {
  if (args.length != 1) {
    print('Usage: example <token>');
    exit(-1);
  }
  var token = args[0];
  var bot = new TelegramBot(token);

  var updates = pollForUpdates(bot);

  await for (var update in updates) {
    if (update.inlineQuery != null) {
      handleInlineQuery(bot, update.inlineQuery);
    }
    if (update.message != null) {
      handleMessage(bot, update.message);
    }
  }
}

void handleMessage(TelegramBot bot, Message message) {
  bot.sendCommand(new SendMessage.plainText(message.chat.id,
      "Hello, I'm just a bot. Don't expect too much from me."));
}

const _pageSize = 10;

void handleInlineQuery(TelegramBot bot, InlineQuery inlineQuery) {
  var offset =
      (inlineQuery.offset ?? '').isEmpty ? 0 : int.parse(inlineQuery.offset);

  var results = <InlineQueryResult>[];
  var i = offset;
  for (; i < inlineQuery.query.runes.length && i - offset < _pageSize; i++) {
    results.add(
      new InlineQueryResultArticle(
          '$i',
          'At least ${i+1}',
          new InputTextMessageContent.markdown(
              'The sent text contains _at least_ ${i+1} characters.')),
    );
  }
  var nextOffset = i < inlineQuery.query.length ? '$i' : null;
  bot.sendCommand(new AnswerInlineQuery(
    inlineQuery.id,
    results,
    nextOffset: nextOffset,
    switchPmText: 'Chat with me',
    switchPmParameter: 'chat',
  ));
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  telegrambot: ^0.1.0

2. Install it

You can install packages from the command line:

with pub:


$ pub get

Alternatively, your editor might support pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:telegrambot/telegrambot.dart';
  
Version Uploaded Documentation Archive
0.1.0 Sep 22, 2017 Go to the documentation of telegrambot 0.1.0 Download telegrambot 0.1.0 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
34
Health:
Code health derived from static analysis. [more]
0
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
0
Overall:
Weighted score of the above. [more]
17
Learn more about scoring.

The package version is not analyzed, because it does not support Dart 2. Until this is resolved, the package will receive a health and maintenance score of 0.

Issues and suggestions

Support Dart 2 in pubspec.yaml.

The SDK constraint in pubspec.yaml doesn't allow the Dart 2.0.0 release. For information about upgrading it to be Dart 2 compatible, please see https://www.dartlang.org/dart-2#migration.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.24.2 <2.0.0