skrepr / teams-connector

一个简单的PHP包,用于向Microsoft Teams发送消息

0.3.2 2023-02-09 17:09 UTC

This package is auto-updated.

Last update: 2024-09-09 20:44:39 UTC


README

skrepr

团队连接器

Releases LICENSE Issues PR Commits Stars Forks

此包允许您向Microsoft Teams发送通知。

安装

您可以使用Composer包管理器安装此包。您可以在项目根目录中运行以下命令来安装它:

composer require skrepr/teams-connector

然后,为该包在您的Microsoft Teams渠道上创建一个入站Webhook

基本用法

创建一个简单的卡片

<?php

declare(strict_types=1);

use Skrepr\TeamsConnector\Card;
use Skrepr\TeamsConnector\CardInterface;
use Skrepr\TeamsConnector\Client;

$endPoint = 'https://...';
$httpClient = new \GuzzleHttp\Client();
$teamsClient = new Client($endPoint, $httpClient);

$card = (new Card('Larry Bryant created a new task'))
    ->setText('Yes, he did')
    ->setThemeColor(CardInterface::STATUS_DEFAULT)
    ->setTitle('Adding Title to the card');

$teamsClient->send($card);

添加一个部分

<?php

declare(strict_types=1);

use Skrepr\TeamsConnector\Card;
use Skrepr\TeamsConnector\Client;
use Skrepr\TeamsConnector\Section\Section;

$endPoint = 'https://...';
$httpClient = new \GuzzleHttp\Client();
$teamsClient = new Client($endPoint, $httpClient);

$card = new Card('Larry Bryant created a new task');

$section = (new Section('![TestImage](https://47a92947.ngrok.io/Content/Images/default.png)Larry Bryant created a new task'))
    ->setActivitySubtitle('On Project Tango')
    ->setActivityImage('https://teamsnodesample.azurewebsites.net/static/img/image5.png')
    ->addFact('Assigned to', 'Unassigned')
    ->addFact('Due date', 'Mon May 01 2017 17:07:18 GMT-0700 (Pacific Daylight Time)');

$card->addSection($section);

$teamsClient->send($card);

向卡片添加操作和输入

<?php

declare(strict_types=1);

use Skrepr\TeamsConnector\Actions\ActionCard;
use Skrepr\TeamsConnector\Actions\HttpPostAction;
use Skrepr\TeamsConnector\Card;
use Skrepr\TeamsConnector\Client;
use Skrepr\TeamsConnector\Inputs\TextInput;

$endPoint = 'https://...';
$httpClient = new \GuzzleHttp\Client();
$teamsClient = new Client($endPoint, $httpClient);

$card = new Card('Larry Bryant created a new task');
$card->setText('Yes, he did');

$actionCard = (new ActionCard('Add a comment'))
    ->addInput(new TextInput('comment', 'Add a comment here for this task'))
    ->addAction(new HttpPostAction('Add comment', 'http://...'));

$card->addPotentialAction($actionCard);

$teamsClient->send($card);

HTTP客户端

为了与Microsoft Teams API通信,您需要一个HTTP适配器。我们依赖于HTTPlug,它定义了如何发送和接收HTTP消息。您可以使用实现php-http/client-implementation的任何库来发送HTTP消息。

测试

composer test

致谢

安全漏洞

请查阅我们关于如何报告安全漏洞的安全策略

许可

MIT许可(MIT)。有关更多信息,请参阅许可文件