telegrambot 0.1.0

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

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',
  ));
}

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

with Flutter:


$ flutter packages get

Alternatively, your editor might support pub get or packages 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

Analysis

We analyzed this package on Apr 23, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0-dev.49.0
  • pana: 0.10.6

Scores

Popularity:
Describes how popular the package is relative to other packages. [more]
20 / 100
Health:
Code health derived from static analysis. [more]
61 / 100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
98 / 100
Overall score:
Weighted score of the above. [more]
48
Learn more about scoring.

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in primary library package:telegrambot/telegrambot.dart.

Suggestions

  • Fix analysis and formatting issues.

    Analysis or formatting checks reported 4 errors 12 hints.

    Strong-mode analysis of lib/src/impl/model.dart failed with the following error:

    line: 1017 col: 31
    The argument type '(Map<String, Object>) → _User' can't be assigned to the parameter type '(dynamic) → User'.

    Strong-mode analysis of lib/src/impl/annotation.dart gave the following hint:

    line: 26 col: 40
    Unnecessary cast.

    Similar analysis of the following files failed:

    • lib/src/impl/util.dart (hint)
  • The description is too short.

    Add more detail about the package, what it does and what is its target use case. Try to write at least 60 characters.

  • Package is pre-v1 release.

    While there is nothing inherently wrong with versions of 0.*.*, it usually means that the author is still experimenting with the general direction API.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.24.2 <2.0.0
http ^0.11.3+14 0.11.3+16
Transitive dependencies
async 2.0.6
charcode 1.1.1
collection 1.14.9
http_parser 3.1.1
path 1.5.1
source_span 1.4.0
string_scanner 1.0.2
typed_data 1.1.5
Dev dependencies
test ^0.12.0