paperplane 0.5.1

  • Readme
  • Changelog
  • Example
  • Installing
  • new66

PaperPlane

Just a Telegram Library for Dart. A package to interact with the official

Telegram Bot API.

Dart Version Build Status Bot API Nebulino

Disclaimer #

I'm doing it just for fun, so... use at your own risk.

I hope it will become something great.

^-^

Usage #

First build the .g files for Serializable (if you clone the repo):

pub run build_runner build

A simple usage example:

import 'dart:io' as io;
import 'package:paperplane/paperplane.dart';

void main() {
  var token = 'Just A Token';
  
  var bot = PaperPlane.createBot(token);
  bot.engine();

  bot.startPolling();
  
  // Work with events...
  bot
    .onMessage()
    .where((message) => message.text == 'owo')
    .listen((message) => message.replyText(text: 'uwu'));
 
  // Work with updates and directly with methods...
  var api = bot.api;
  var updater = bot.updater.onUpdate();
  
  updater
    .where((onUpdate) => onUpdate.message.text == 'animate')
    .listen((update) => methods.sendAnimation(
      chat_id: message.chat.id,
      animation: Luggage.withFile(file: io.File('./files/gifs/bunny_girl.gif'))));
}

Get PaperPlane #

Add PaperPlane dependency on pubspec.yaml:

From GitHub:

dependencies:
  paperplane:
    git: https://github.com/Nebulino/PaperPlane.git
    ref: branch-name

From pub.dev:

dependencies:
  paperplane: ^0.5.1

Features and bugs #

All API up-to v4.6 are supported.

Implemented a base for a future solid implementation of Long Polling.

Still not implemented the Webhook.

You can use Long Polling mode for now.

I have created all Telegram API Classes for each Telegram Types.

Please file feature requests and bugs at the issue tracker.

0.5.1 #

  • Fixed a problem with the dispatcher.
  • Cleaned some part of code.
  • Hide the TelegramClient part.
  • Removed UUID package and created just a simple String Generator Helper.

0.5.0 #

Huge package rewrite.

Now all Telegram API v4.6 are supported.
  • Fixed sendMediaGroup.
  • Started using Dio as HTTPClient => TelegramClient.
  • Rewritten Response Class => TelegramResponse.
  • Created more Helpers such as Luggage and InputMediaLuggage for better File management.
  • Created more Extensions.
  • Duration is now only Duration type.
  • Written some function in PaperPlane.dart for managing LongPolling.
  • Rewritten some part of the package.
  • Refactored some functions.
  • Testing a ChatIdentifier object to manage functions that accepts int chat_id and String chat_id (for groups and channels).
  • Remove some un-necessary exceptions.
  • Rewritten "clean" scripts.
  • More to come...

0.4.4 #

  • Fixed the example.
  • Added MessageEntityType.
  • Fixed export.

0.4.3 #

  • Implemented clean mode polling.
  • Implemented bot stopping.
  • Fixed blob sending.

0.4.2 #

Another update.

  • Fixed Telegram API v.4.6.
  • Created PollAnswer.
  • Created KeyboardButtonPollType.
  • Updated Update object.
  • Updated MessageEntity.
  • Fixed CHANGELOG.md.

0.4.1 #

A new step for the docs, and more...

  • Updated some methods.
  • Created some extensions.
  • Updated all Telegram API types documentation.
  • Implemented replyLocation.
  • Some refactoring.

0.4.0 #

Huge Update. Basic polling!

  • Implemented a basic long polling implementation.
  • To achieve this, created Updater.
  • Created messages dispatcher.
  • Created message extension.
  • Refactored some part of the code.

0.3.0 #

Big update.

  • Finished implementing all Telegram Api Methods.
  • TODO: make possible using @username in chat_id in some methods.

0.2.2 #

  • Implemented more methods.
  • Modified some docs.
  • Created PollType for Telegram 4.6.

0.2.1 #

  • TODO: create a list of implemented methods.
  • Changed the version on pubspec.yaml.

0.2.0 #

Big update.

  • Modified PaperPlane class, it can make bots now.
  • Created Telegram Class, it helps bridging PaperPlane and Telegram Api methods.
  • Created methods class, it contains Telegram Api methods needs to be completed.
  • Created chat_actions class.
  • Created parse_mode class.
  • Created some helpers such as bot_file, constant and paperplane_bot local type.
  • Fixed the previous commit, without http_client class.

0.1.3 #

  • Created HTTP Client class in tools.
  • Created Exceptions Classes in exceptions.
  • Added some docs for Telegram API types and other classes.
  • Updated README.md.

0.1.2 #

  • Created a 'publish' branch for publishing into pub.dev.

0.1.1 #

  • Created a 'dev' branch to keep the repo tidy.
  • Preparing for publishing on pub.dev.
  • Added LICENSE.

0.1.0 #

Pre-release

  • First Pre-release, no Telegram methods implemented.
  • Modified the README.md to make it more appealing.
  • Created all Telegram API types Classes.
  • Added functions in each types fromJson and toJson.
  • Added some Script for building and cleaning.

0.0.1 #

  • Initial version. Created the Package's repo structure.

example/paperplane_example.dart

/**
 * PaperPlane - Just a Telegram Library for Dart
 * Copyright (c) 2020 Nebulino
 */

import 'dart:io' as io;

import 'package:logger/logger.dart';
import 'package:paperplane/helpers.dart';
import 'package:paperplane/paperplane.dart';

import 'test_values.dart';

/// A simple Example...
void main() {
  // => Choose how to create your bot~:
  // - BotFile (async)
  // - io.File
  // - token
  var paperplane = PaperPlane.createBot(token: TestValues.TOKEN);
  final master = TestValues.MASTER;
  final dev_lab = TestValues.DEV;

  // => Turn on the engines. Okay it's a paperplane, but still looks cool?
  // If you want to export the bot for future use when turning off.
  // I know, this example loads a file, but I guess you know that exporting is
  // good if you create a bot using a TOKEN for example.
  paperplane.engine()
    ..then((bot) => paperplane.export(bot: bot, file_name: 'bot.json'))
    ..then((bot) => paperplane.api.getChat(chat_id: master).then(
        (master_data) => paperplane.api.sendMessage(
            chat_id: master,
            text: "I'm departed master ${master_data.username}...")));

  paperplane.setLoggerLevel(level: Level.debug);

  // => Choose your "flying" mode:
  // - polling
  // - webhook (to be implemented)
  paperplane.startPolling(clean: true);

  // => Do you want to work directly with Telegram Methods and shrink the code?
  final api = paperplane.api;

  // => If you want to work with updates, you can!
  // 1. get the updater.
  final updater = paperplane.updater.onUpdate();

  // 2. set your conditions!
  updater
      .where((onUpdate) => onUpdate.message.text != null)
      .where((onUpdate) => onUpdate.message.text == 'uwu')
      .listen((update) {
    api.sendMessage(chat_id: update.message.chat.id, text: 'owo');
  });

  // => If you want to manage events, just do as follows...
  paperplane
      .onMessage()
      .where((message) => message.text == 'cacca')
      .listen((message) {
    api.sendPhoto(
        // Send an image from a URL.
        chat_id: message.chat.id,
        photo: Luggage.withLink(
            link: 'https://pbs.twimg.com/media/ETObHKAUUAE7nSM.jpg'));
  });

  paperplane.onMessage().where((message) => message.text == 'voice').listen(
      (message) => api.sendAudio(
          // Send a File. You can also send a blob (Uint8List).
          chat_id: message.chat.id,
          audio:
              Luggage.withFile(file: io.File('./files/voices/kokodayo.ogg'))));

  // For more information about the methods, watch the wiki
  // (on pub.dev: https://pub.dev/packages/paperplane)!

  // you can also directly reply a message entity if you want...
  paperplane
      .onMessage()
      .where((message) => message.text == 'reply')
      .listen((message) {
    message.replyText(text: 'sure!');
  });

  // MORE TO COME... STAY SAFE AND FLY~ (Corona Virus FREE PaperPlanes)
}

Use this package as a library

1. Depend on it

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


dependencies:
  paperplane: ^0.5.1

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

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

3. Import it

Now in your Dart code, you can use:


import 'package:paperplane/paperplane.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
32
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
66
Learn more about scoring.

We analyzed this package on Mar 28, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.6

Health suggestions

Format lib/src/paperplane/helpers/constant.dart.

Run dartfmt to format lib/src/paperplane/helpers/constant.dart.

Format lib/src/telegram/poll.dart.

Run dartfmt to format lib/src/telegram/poll.dart.

Format lib/src/telegram/user.dart.

Run dartfmt to format lib/src/telegram/user.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.7.0 <3.0.0
dio ^3.0.9 3.0.9
json_annotation ^3.0.1 3.0.1
logger ^0.8.3 0.8.3
meta ^1.1.8 1.1.8
path ^1.6.4 1.6.4
Transitive dependencies
charcode 1.1.3
collection 1.14.12
http_parser 3.1.4
io 0.3.3
source_span 1.7.0
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6
Dev dependencies
build_runner ^1.8.0
json_serializable ^3.3.0
matcher ^0.12.6
mockito ^4.1.1
pedantic ^1.9.0
test ^1.14.2