telegrambot 0.1.0

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

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

This feature is new.
We welcome feedback.
More details: scoring.

We analyzed this package, and provided a score, details, and suggestions below.

  • completed on Feb 3, 2018
  • Dart: 2.0.0-dev.20.0
  • pana: 0.10.1

Scores

Popularity:
Describes how popular the package is relative to other packages. [more]
18 / 100
Health:
Code health derived from static analysis. [more]
90 / 100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100 / 100
Overall score:
Weighted score of the above. [more]
56

Platforms

Detected platforms: Flutter, web, other

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

Suggestions

  • 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.3
charcode 1.1.1
collection 1.14.5
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