定制 kodeops/laravel-telegram-wrapper 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

kodeops/laravel-telegram-wrapper

Composer 安装命令:

composer require kodeops/laravel-telegram-wrapper

包简介

Laravel Telegram API wrapper.

README 文档

README

 _     _  _____  ______  _______  _____   _____  _______
 |____/  |     | |     \ |______ |     | |_____] |______
 |    \_ |_____| |_____/ |______ |_____| |       ______|
 

Laravel Telegram API Wrapper

This package is a wrapper for the Telegram API.

Install composer dependency

$ composer require kodeops/laravel-telegram-wrapper

Setup logging

Add a new channel in logging.php config file:

'telegram' => [
    'driver' => 'single',
    'path' => storage_path('logs/telegram.log'),
    'level' => 'info',
],

Add environment settings

These would be used by default, additionally you can pass the credentials when instantiating the object.

TELEGRAM_DEBUG=false
TELEGRAM_BOT_TOKEN=<token>
TELEGRAM_CHAT_ID=<chat_id>

Usage

Send a new message

use kodeops\LaravelTelegramWrapper\Telegram;

return (new Telegram())
    ->withMarkdown($markdown)
    ->sendMessage();

You can also specify the credentials (bot_token and chat_id) when instantiating the object.

use kodeops\LaravelTelegramWrapper\Telegram;

return (new Telegram($bot_token))
    ->chat($chat_id)
    ->withMarkdownImage($image)
    ->withKeyboard($keyboard)
    ->withMarkdown($markdown)
    ->sendMessage();

This produces a message with the image on top and uses the image for notification highlight.

use kodeops\LaravelTelegramWrapper\Telegram;

$keyboard = [
    'inline_keyboard' => [
        [
            [
                'text' => 'Text Button',
                'url' => 'https://tannhauser-gate.xyz',
            ],
        ]
    ]
];

$markdown = 'A simple *markdown* text';
$image = 'https://iibusiness.s3.eu-central-1.amazonaws.com/tannhauser/favicon.jpg';

return (new Telegram())
    ->withKeyboard($keyboard)
    ->withMarkdownCaption($markdown)
    ->sendPhoto($image);

Options for sending messages:

  • disableWebPagePreview(): Disables link previews for links in this message

  • withKeyboard($keyboard): Sets the keyboard for a message

  • withMarkdown($markdown): Sets the markdown text

  • withMarkdownImage($image): Sets an image to the message using markdown

  • withMarkdownCaption($markdown): Sets a markdown text as a caption (useful in combination with sendPhoto($image))

Utils

  • setMyCommands($commands): set bot commands

  • setWebhook($url): set webhooks url More info on webhooks

  • getWebhookInfo(): get webhooks info

Additional features

In general you can use setParam($key, $value) method to add parameters to the request.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-04-08

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固