2017 © Pedro Pelรกez
 

framework framebot

Telegram bot framework written in PHP.

image

banghasan/framebot

Telegram bot framework written in PHP.

  • Friday, January 6, 2017
  • by banghasan
  • Repository
  • 1 Watchers
  • 4 Stars
  • 13 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 17 Forks
  • 0 Open issues
  • 7 Versions
  • 8 % Grown

The README.md

Framebot

Telegram bot framework menggunakan bahasa pemrograman PHP, merupakan fork dari PHPTelebot yang sudah disesuaikan untuk kebutuhan proyek internal., (*1)

Tujuan

Sebagai bahan ebook III Bot Telegram - Versi Final!, (*2)

Fitur

  • Simple, mudah digunakan.
  • Support Long Polling dan Webhook.

Tambahan

  • Support inisiasi dipergunakan untuk session
  • Support finalisasi untuk akhir aktifitas (penyimpanan session, dll)

Kebutuhan

Installasi

Menggunakan Composer

Install Framebot dengan Composer, tambahkan file composer.json seperti berikut :, (*3)

{
    "require": {
        "banghasan/framebot": "*"
    }
}

atau jalankan perintah berikut lewat CLI:, (*4)

composer require banghasan/framebot

Composer akan menginstall autoloader di ./vendor/autoloader.php. Untuk di-include ke codinganmu, tambahkan:, (*5)

require_once 'vendor/autoload.php';

Install dari Sumber Code

Download Framebot ini dari Github, kemudian include FrameBot.php in your script:, (*6)

require_once '/path/to/framebot/src/FrameBot.php';

Usage

Creating a simple bot

<?php

require_once './src/FrameBot.php';
$bot = new FrameBot('TOKEN', 'BOT_USERNAME'); // Bot username is optional, its required for handle command that contain username (/command@username) like on a group.

// Simple command
$bot->cmd('*', 'Hi, human! I am a bot.');

// Simple echo command
$bot->cmd('/echo|/say', function ($text) {
    if ($text == '') {
        $text = 'Command usage: /echo [text] or /say [text]';
    }
    return Bot::sendMessage($text);
});

// Simple whoami command
$bot->cmd('/whoami|!whoami', function () {
    // Get message properties
    $message = Bot::message();
    $name = $message['from']['first_name'];
    $userId = $message['from']['id'];
    $text = 'You are <b>'.$name.'</b> and your ID is <code>'.$userId.'</code>';
    $options = [
        'parse_mode' => 'html',
        'reply' => true
    ];

    return Bot::sendMessage($text, $options);
});

$bot->run();

Then run, (*7)

php file.php

You can also see my other sample., (*8)

NOTE: - If function parameters is more than one, FrameBot will split text by space. - If you don't set chat_id on options bot will send message to current chat. - If you add option reply => true, bot will reply current message (Only work if you don't set custom chat_id and reply_to_mesage_id)., (*9)

Commands

Use $bot->cmd(<command>, <function>) to handle command., (*10)

// simple answer
$bot->cmd('*', 'I am a bot');

// catch multiple commands
$bot->cmd('/start|/help', function () {
   // Do something here.
});

// call a function name
function googleSearch($search) {
   // Do something here.
}
$bot->cmd('/google', 'googleSearch');

Use * to catch any command., (*11)

File upload

This code will send a photo to users when type command /upload., (*12)

// Simple photo upload
$bot->cmd('/upload', function () {
    $file = '/path/to/photo.png'; // File path, file id, or url.
    return Bot::sendPhoto($file);
});

Events

Use $bot->on(<event>, <function>) to handle all possible FrameBot events., (*13)

To handle inline message, just add:, (*14)

$bot->on('inline', function($text) {
    $results[] = [
        'type' => 'article',
        'id' => 'unique_id1',
        'title' => $text,
        'message_text' => 'Lorem ipsum dolor sit amet',
    ];
    $options = [
        'cache_time' => 3600,
    ];

    return Bot::answerInlineQuery($results, $options);
});

Also, you can catch multiple events:, (*15)

$bot->on('sticker|photo|document', function() {
  // Do something here.
 });

Supported events:

  • * - any type of message
  • text โ€“ text message
  • audio โ€“ audio file
  • voice โ€“ voice message
  • document โ€“ document file (any kind)
  • photo โ€“ photo
  • sticker โ€“ sticker
  • video โ€“ video file
  • contact โ€“ contact data
  • location โ€“ location data
  • venue โ€“ venue data
  • edited โ€“ edited message
  • pinned_message โ€“ message was pinned
  • new_chat_member โ€“ new member was added
  • left_chat_member โ€“ member was removed
  • new_chat_title โ€“ new chat title
  • new_chat_photo โ€“ new chat photo
  • delete_chat_photo โ€“ chat photo was deleted
  • group_chat_created โ€“ group has been created
  • channel_chat_created โ€“ channel has been created
  • supergroup_chat_created โ€“ supergroup has been created
  • migrate_to_chat_id โ€“ group has been migrated to a supergroup
  • migrate_from_chat_id โ€“ supergroup has been migrated from a group
  • inline - inline message
  • callback - callback message
  • game - game
  • channel - channel
  • edited_channel - edited channel post

Command with custom regex (advanced)

Create a command: /regex string number, (*16)

$bot->regex('/^\/regex (.*) ([0-9])$/i', function($matches) {
    // Do something here.
});

Methods

FrameBot Methods

cmd(<command>, <answer>)

Handle a command., (*17)

on(<event>, <answer>)

Handles events., (*18)

regex(<regex>, <answer>)

Create custom regex for command., (*19)

Bot::type()

Return message event type., (*20)

Bot::message()

Get message properties., (*21)

Telegram Methods

FrameBot use standard Telegram Bot API method names., (*22)

Bot::getMe() ?

A simple method for testing your bot's auth token., (*23)

Bot::sendMessage(<text>, <options>) ?

Use this method to send text messages., (*24)

Bot::forwardMessage(<options>) ?

Use this method to forward messages of any kind., (*25)

Bot::sendPhoto(<file path | file id | url>, <options>) ?

Use this method to send a photo., (*26)

Bot::sendVideo(<file path | file id | url>, <options>) ?

Use this method to send a video., (*27)

Bot::sendAudio(<file path | file id | url>, <options>) ?

Use this method to send a audio., (*28)

Bot::sendVoice(<file path | file id | url>, <options>) ?

Use this method to send a voice message., (*29)

Bot::sendDocument(<file path | file id | url>, <options>) ?

Use this method to send a document., (*30)

Bot::sendSticker(<file path | file id | url>, <options>) ?

Use this method to send a sticker., (*31)

Bot::sendLocation(<options>) ?

Use this method to send point on the map., (*32)

Bot::sendVenue(<options>) ?

Use this method to send information about a venue., (*33)

Bot::sendContact(<options>) ?

Use this method to send phone contacts., (*34)

Bot::sendAction(<action>, <options>) ?

Use this method when you need to tell the user that something is happening on the bot's side., (*35)

Bot::getUserProfilePhotos(<user id>, <options>) ?

Use this method to get a list of profile pictures for a user., (*36)

Bot::getFile(<file id>) ?

Use this method to get basic info about a file and prepare it for downloading. For the moment, bots can download files of up to 20MB in size., (*37)

Bot::answerInlineQuery(<array of results>, <options>) ?

Use this method to send answers to an inline query., (*38)

Bot::answerCallbackQuery(<text>, <options>) ?

Use this method to send answers to callback queries sent from inline keyboards., (*39)

Bot::getChat(<chat_id>) ?

Use this method to get up to date information about the chat., (*40)

Bot::leaveChat(<chat_id>) ?

Use this method for your bot to leave a group, supergroup or channel., (*41)

Bot::getChatAdministrators(<chat_id>) ?

Use this method to get a list of administrators in a chat., (*42)

Bot::getChatMembersCount(<chat_id>) ?

Use this method to get the number of members in a chat., (*43)

Bot::getChatMember(<options>) ?

Use this method to get information about a member of a chat., (*44)

Bot::kickChatMember(<options>) ?

Use this method to kick a user from a group or a supergroup., (*45)

Bot::unbanChatMember(<options>) ?

Use this method to unban a previously kicked user in a supergroup., (*46)

Bot::editMessageText(<options>) ?

Use this method to edit text messages sent by the bot or via the bot (for inline bots)., (*47)

Bot::editMessageCaption(<options>) ?

Use this method to edit captions of messages sent by the bot or via the bot (for inline bots)., (*48)

Bot::editMessageReplyMarkup(<options>) ?

Use this method to edit only the reply markup of messages sent by the bot or via the bot (for inline bots)., (*49)

Bot::sendGame(<game short name>, <options>) ?

Use this method to send a game., (*50)

Bot::setGameScore(<options>) ?

Use this method to set the score of the specified user in a game., (*51)

Bot::getGameHighScores(<user id>, <options>) ?

Use this method to get data for high score tables., (*52)

Webhook installation

Open via browser https://api.telegram.org/bot<BOT TOKEN>/setWebhook?url=https://yourdomain.com/your_bot.php, (*53)

The Versions

06/01 2017

dev-master

9999999-dev

Telegram bot framework written in PHP.

  Sources   Download

GPL-3.0

The Requires

  • php >=5.4
  • ext-curl *

 

by Avatar banghasan

bot telegram

06/01 2017

dev-analysis-zDLblL

dev-analysis-zDLblL

Telegram bot framework written in PHP.

  Sources   Download

GPL-3.0

The Requires

  • php >=5.4
  • ext-curl *

 

by Avatar banghasan

bot telegram

05/01 2017

1.5

1.5.0.0

Telegram bot framework written in PHP.

  Sources   Download

GPL-3.0

The Requires

  • php >=5.4
  • ext-curl *

 

by Avatar banghasan

bot telegram

29/11 2016

v1.3

1.3.0.0

Telegram bot framework written in PHP.

  Sources   Download

GPL-3.0

The Requires

  • php >=5.4
  • ext-curl *

 

by Radya

bot telegram

22/11 2016

v1.2

1.2.0.0

Telegram bot framework written in PHP.

  Sources   Download

GPL-3.0

The Requires

  • php >=5.4
  • ext-curl *

 

by Radya

bot telegram

17/11 2016

v1.1

1.1.0.0

Telegram bot framework written in PHP.

  Sources   Download

GPL-3.0

The Requires

  • php >=5.4
  • ext-curl *

 

by Radya

bot telegram

11/11 2016

v1

1.0.0.0

Telegram bot framework written in PHP.

  Sources   Download

GPL-3.0

The Requires

  • php >=5.4
  • ext-curl *

 

by Radya

bot telegram