PHP code example of rocketfellows / ms-teams-webhook-message-sender
1. Go to this page and download the library: Download rocketfellows/ms-teams-webhook-message-sender library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
rocketfellows / ms-teams-webhook-message-sender example snippets
public function sendMessage(Connector $connector, Message $message): void;
$sender->sendMessage(Connector::create(INCOMING_WEBHOOK_URL), Message::create('Hello world!', 'Hello!'));
$sender->sendMessage(Connector::create(INCOMING_WEBHOOK_URL), Message::create('Hello world!'));
public function sendText(Connector $connector, string $text): void;
$sender->sendText(Connector::create(INCOMING_WEBHOOK_URL), 'Hello world!');
public function sendMessageFromArray(Connector $connector, array $messageData): void;
$sender->sendMessageFromArray(
Connector::create(INCOMING_WEBHOOK_URL),
[
'text' => 'Hello world!',
'title' => 'Hello!',
]
);
$sender->sendMessageFromArray(
Connector::create(INCOMING_WEBHOOK_URL),
[
'text' => 'Hello world!',
]
);
$sender->sendMessageFromArray(
Connector::create(INCOMING_WEBHOOK_URL),
[
'text' => 'Hello world!',
'sections' => [
[
"activityTitle" => "Larry Bryant created a new task",
"activitySubtitle" => "On Project Tango",
"activityImage" => "https://adaptivecards.io/content/cats/3.png",
"facts" => [
[
"name" => "Assigned to",
"value" => "Unassigned",
],
[
"name" => "Due date",
"value" => "Mon May 01 2017 17:07:18 GMT-0700 (Pacific Daylight Time)"
],
[
"name" => "Status",
"value" => "Not started"
]
],
"markdown" => true,
]
],
]
);
public function sendJsonMessage(Connector $connector, string $jsonMessage): void;
$sender->sendJsonMessage(
Connector::create(INCOMING_WEBHOOK_URL),
'{"text": "Hello world!", "title": "Hello!"}'
);
$sender->sendJsonMessage(
Connector::create(INCOMING_WEBHOOK_URL),
'{"text": "Hello world!"}'
);
$sender->sendJsonMessage(
Connector::create(INCOMING_WEBHOOK_URL),
'{
"text": "Hello world!",
"sections": [
{
"activityTitle": "Larry Bryant created a new task",
"activitySubtitle": "On Project Tango",
"activityImage": "https://adaptivecards.io/content/cats/3.png",
"facts": [
{
"name": "Assigned to",
"value": "Unassigned"
},
{
"name": "Due date",
"value": "Mon May 01 2017 17:07:18 GMT-0700 (Pacific Daylight Time)"
},
{
"name": "Status",
"value": "Not started"
}
],
"markdown": true
}
]
}'
);
$sender = new MSTeamsWebhookMessageSender(new \GuzzleHttp\Client());
$sender->sendMessage(Connector::create(INCOMING_WEBHOOK_URL), Message::create('Hello world!'));
$sender = new MSTeamsWebhookMessageSender(new \GuzzleHttp\Client());
$sender->sendMessage(
Connector::create(INCOMING_WEBHOOK_URL),
Message::create('Hello world!', 'Hello!')
);
$sender = new MSTeamsWebhookMessageSender(new \GuzzleHttp\Client());
$sender->sendText(
Connector::create(INCOMING_WEBHOOK_URL),
'Hello world!'
);
$sender = new MSTeamsWebhookMessageSender(new \GuzzleHttp\Client());
$sender->sendMessageFromArray(
Connector::create(INCOMING_WEBHOOK_URL),
[
'title' => 'Message title',
'text' => 'Hello world!',
]
);
$sender = new MSTeamsWebhookMessageSender(new \GuzzleHttp\Client());
$sender->sendJsonMessage(
Connector::create(INCOMING_WEBHOOK_URL),
'{"title": "Message title", "text": "Hello world!"}'
);