prowebcraft/telebot

Telegram bot with dialogs and session management

0.7.0 2020-05-23 08:43 UTC

This package is auto-updated.

Last update: 2024-04-19 05:40:33 UTC


README

Telegram bot with dialogs support and session management

PHP Telegram Bot Api

Latest Version on Packagist Software License Total Downloads

Based on php wrapper for Telegram Bot API, telebot provides flexible diablogs system (inlines and buttons mode), ability to track responses. Telebot can work in daemon or webhook mode.

Bots: An introduction for developers

Bots are special Telegram accounts designed to handle messages automatically. Users can interact with bots by sending them command messages in private or group chats.

You control your bots using HTTPS requests to bot API.

The Bot API is an HTTP-based interface created for developers keen on building bots for Telegram. To learn how to create and set up a bot, please consult Introduction to Bots and Bot FAQ.

Install

Via Composer

$ composer require prowebcraft/telebot

Usage

See example Telegram Id Bot. This bot in Telegram - @identybot

Create your bot YourBot.php class extended of \Prowebcraft\Telebot\Telebot

<?php

class YourBot extends \Prowebcraft\Telebot\Telebot
{

}

####Create some public methods with Command suffix

/**
* Welcome message based on context
*/
public function hiCommand()
{
    if ($this->isChatGroup()) {
        $this->reply('Hey everybody in this chat!');
    } else {
        $this->reply('Hello, human!');
    }
}

####Run your bot in daemon mode. Create daemon.php

<?php

require_once './vendor/autoload.php';
require_once "YourBot.php";

$config = [];
$bot = new YourBot('YourBotName', []);
$bot->start();

And run it in console

$ php daemon.php

At first run data.json will be created with some template options:

{
  "config": {
    "api": "TELEGRAM_BOT_API_KEY",
    "globalAdmin": 70863438,
    "admins": [],
    "trust": [],
    "whiteGroups": []
  }
}

Set your bot token to config.api

Set yourself as global admin (you can get your id from @identybot)

Send /hi to your bot

Credits

License

The MIT License (MIT). Please see License File for more information.