mitokande/php-telegram 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

mitokande/php-telegram

最新稳定版本:1.0.2

Composer 安装命令:

composer require mitokande/php-telegram

包简介

a php package to send telegram bot messages

README 文档

README

#PHP TELEGRAM By Mithat Can Turan

V1.0.2

What's new?

-Now you can create your bot with TelegramBotCreator Class.

-Added sending multiple message functionality to TelegramBot Class.

First import my package with composer

composer require mitokande/php-telegram
use Mitokande\PhpTelegram\TelegramBotCreator;
use Mitokande\PhpTelegram\TelegramMessage;

TelegramBotCreator::SetTelegramBot(__Your_Token__);
TelegramBotCreator::$TelegramBot->SendTelegramMessage(new TelegramMessage(__RECEIVER_CHAT_ID__, __YOUR_MESSAGE_));

For sending a message to multiple users at once:

use Mitokande\PhpTelegram\TelegramBotCreator;
use Mitokande\PhpTelegram\TelegramMessage;

TelegramBotCreator::SetTelegramBot(__Your_Token__);
TelegramBotCreator::$TelegramBot->SendMultipleTelegramMessage(__ARRAY_OF_CHAT_ID_STRINGS__, __YOUR_MESSAGE__);

If you were to use it in a class you can create your bot in the construct of your class and just use the static bot variable inside it in all of your methods.

use Mitokande\PhpTelegram\TelegramBotCreator;
use Mitokande\PhpTelegram\TelegramMessage;
use Mitokande\PhpTelegram\TelegramMessageResult;

class TelegramMessager
{
    public function __construct()
    {
        TelegramBotCreator::SetTelegramBot(__Your_Token__);
    }

    public function SendWelcomeMessage($chat_id): TelegramMessageResult
    {
        $bot = TelegramBotCreator::$TelegramBot;
        return $bot->SendTelegramMessage(new TelegramMessage($chat_id, __WELCOME_MESSAGE_FOR_USERS__));
    }
    public function SendPingMessage($chat_id): TelegramMessageResult
    {
        return TelegramBotCreator::$TelegramBot->SendTelegramMessage(new TelegramMessage(__RECEIVER_CHAT_ID__, __YOUR_MESSAGE_));
    }
    public function SendMultiplePingMessage($chat_id_list): TelegramMessageResult
    {
        return TelegramBotCreator::$TelegramBot->SendMultipleTelegramMessage($chat_id_list, __YOUR_MESSAGE_));
    }
}

V1.0.1 First import my package with composer

composer require mitokande/php-telegram@1.0.2

Than in your code import the required classes

use Mitokande\PhpTelegram\TelegramBot;
use Mitokande\PhpTelegram\TelegramMessage;

Create a Telegram Bot Instance with your Token

$bot = TelegramBot::GetInstance(__Your_Token__);

Keep in mind that any user that you want to send a message must have started a conversation with your bot Create a Telegram Message with a chatID and Message Content

$newMessage = new TelegramMessage(__Your_ChatID__, __Your_Message__);

Send the message with your bot and get TelegramMessageResult

$result = $bot->SendTelegramMessage($newMessage);

统计信息

  • 总下载量: 13
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 7
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 6
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-08-25