PHP code example of lupuscoding / webhook-teams

1. Go to this page and download the library: Download lupuscoding/webhook-teams 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/ */

    

lupuscoding / webhook-teams example snippets


// 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
}
@return array[]