lupuscoding / webhook-teams
一个用于创建 Microsoft Teams 消息的小型库
1.0.1
2021-12-21 23:07 UTC
Requires
- php: >=7.4
- ext-curl: *
- ext-json: *
Requires (Dev)
- phpunit/phpunit: ~9.5
This package is auto-updated.
Last update: 2024-09-22 05:32:55 UTC
README
一个用于创建 Microsoft Teams 消息的小型库。
内容
需求 #
- PHP >= 7.4
安装 #
composer require lupuscoding/webhook-teams
使用 #
创建消息卡片
// Insert uses use LupusCoding\Webhooks\Teams\MessageCard; use LupusCoding\Webhooks\Teams\ThemeColor; // Create the card $card = new MessageCard(); $card->setThemeColor(ThemeColor::SUCCESS) ->setSummary('My summary');
创建消息卡片部分
use LupusCoding\Webhooks\Teams\MessageSection; use LupusCoding\Webhooks\Teams\MessageCard; // Create the section $section = new MessageSection(); $section->setActivityTitle('My activity') ->setActivitySubtitle('This is a subtitle') ->setActivityImage('https://some/image.png') ->addFact('My fact', 'This is awesome') ->setMarkdown(false); // Add section to card $card = new MessageCard(); $card->addSection($section);
创建操作卡片
// Insert uses use LupusCoding\Webhooks\Teams\ActionCard; use LupusCoding\Webhooks\Teams\ThemeColor; // Create the card $card = new ActionCard(); $card->setName('my-action-name') ->setThemeColor(ThemeColor::DEBUG);
创建操作卡片输入
use LupusCoding\Webhooks\Teams\ActionCard; use LupusCoding\Webhooks\Teams\Input\TextInput; // Create the input $input = new TextInput(); $input->setId('input1') ->setTitle('Type something in') ->setMultiline(true) ; // Add input to card $card = new ActionCard(); $card->addInput($input);
创建操作卡片操作
use LupusCoding\Webhooks\Teams\ActionCard; use LupusCoding\Webhooks\Teams\CardAction\HttpPost; // Create the action $action = new HttpPost(); $action->setName('Click me') ->setTarget('http://lupuscoding.de'); // Add action to card $card = new ActionCard(); $card->addAction($action);
发送卡片
use LupusCoding\Webhooks\Teams\MessageCard; $card = new MessageCard(); // Setup the hook url $hookUrl = 'https://webhook.site/253013d5-4960-4857-85c4-596998c26e10'; // Init curl request $ch = curl_init(); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4); curl_setopt($ch, CURLOPT_URL, $hookUrl); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($card)); curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type:application/x-www-form-urlencoded']); // Send request $result = curl_exec($ch); curl_close($ch); // Test result if (curl_errno($ch)) { // Failure } else { // Success }
开发 #
- 每个贡献都应遵守 PSR-2 和 PSR-12。
- 方法必须提供参数类型和返回类型。
- 类属性必须是类型化的。
- 文档块必须只包含描述性信息。
- 如果类型声明不够精确,文档块可以包含参数或返回值的类型声明。
例如:`func(): array` 如果方法返回一个数组的数组或对象,可能不够精确。考虑使用类似 `@return array[]` 或 `@return MyObject[]` 的文档块条目来澄清。
测试 #
首先通过执行以下命令安装 phpunit:
composer install
然后通过执行以下命令启动 phpunit:
vendor/bin/phpunit
进一步测试(可选)
每个测试请求都发送到 Pipedream。此网站处理请求并构建有效的响应。同时,每个请求都会转发到这个 Request Bin,以便您可以查看请求数据。
要检查请求,您可以登录您的 GitHub 账户并复制我的发布的 Webhook 工作流程。请确保在工作流程的 Nodejs 步骤中更改 publicBinUrl 变量,以指向您自己的 Request Bin。
在创建您的 Pipedream Webhook 工作流程后,只需修改 MessageCardTest
和 ActionCardTest
类中的 WEBHOOK_URL
常量即可。