junisan/php-google-chat
Composer 安装命令:
composer require junisan/php-google-chat
包简介
Library to compose notifications for Google Chat in PHP
README 文档
README
A simple library to compose and send messages through Google Chat using Webhook. It allows sending from simple text messages to interactive letters.
SimpleMessage
Once you've got the URL you need to send the hooks to, create the following file. It is the simplest email that can be sent: it sends plain text through the sender.
<?php require_once 'vendor/autoload.php'; $guzzle = new \GuzzleHttp\Client(); $webhooks = [ 'default' => 'https://chat.googleapis.com/v1/spaces/AAAAK4AL5Bg/messages?key=AIzaSyDdI0hCZtE6vySjMm-WEfRq3CPzqKqqsHI&token=3PPfdSFIA_p3ColcvumRTiRnbMftokJhDjz0RJI3sa8%3D' ]; $sender = new \Junisan\GoogleChat\GoogleChatSender($guzzle, $webhooks); $message = \Junisan\GoogleChat\SimpleMessage::create()->addText('Hello'); $sender->send($message, 'default');
The SimpleMessage supports some formatting following the Markdown format:
<?php //... Create sender $message = new \Junisan\GoogleChat\SimpleMessage(); $message ->addText('Hola') ->addLine() ->addBoldText('Como estás') ->addLine() ->addLink('https://www.juannicolas.eu'); $sender->send($message, 'default');
Message
The Message allows you to add cards, sections and some UI components that allow you to create very attractive interfaces and even interact with the user.
$link = \Junisan\GoogleChat\UIElements\TextButton::create('http://google.es', 'Follow'); $link2 = \Junisan\GoogleChat\UIElements\TextButton::create('http://google.es', 'Unfollow'); $link3 = \Junisan\GoogleChat\UIElements\ImageButton::create('http://google.es', 'https://goo.gl/aeDtrS'); $order = \Junisan\GoogleChat\UIElements\KeyValue::create('Order No.', '12345'); $status = \Junisan\GoogleChat\UIElements\KeyValue::create('Status', '12345'); $textParagraph = \Junisan\GoogleChat\UIElements\TextParagraph::create('Hola'); $sectionA = \Junisan\GoogleChat\Elements\Section::create() ->addWidgets($order, $status, $textParagraph, $link3); $sectionB = \Junisan\GoogleChat\Elements\Section::create() ->addWidgets($link, $link2); $card = \Junisan\GoogleChat\Elements\Card::create('Pizza __Bot__', 'pizzabot@example.com', 'https://goo.gl/aeDtrS') ->addSections($sectionA, $sectionB); $cardB = \Junisan\GoogleChat\Elements\Card::create('Hola'); $message = \Junisan\GoogleChat\Message::create() ->addCard($card); $sender->send($message, 'default');
Sender
Sender is the class in charge of sending the instances of the messages that you have created. When building it, you must pass an array containing the different names of the channels and the url, as shown in the following code.
$webhooks = [ 'default' => 'https://chat.googleapis.com/v1/.....', 'another_channel' => 'https://chat.googleapis.com/v1/.....' ]; $sender = new \Junisan\GoogleChat\GoogleChatSender($guzzle, $webhooks);
When you want to send the message, you must call the send method, passing as a parameter the message to send and the name of the channel through which to send that message.
$sender->send($message, 'another_channel');
junisan/php-google-chat 适用场景与选型建议
junisan/php-google-chat 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 211 次下载、GitHub Stars 达 1, 最近一次更新时间为 2023 年 02 月 14 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 junisan/php-google-chat 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 junisan/php-google-chat 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 211
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 6
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-02-14

