PHP code example of sebbmeyer / php-microsoft-teams-connector

1. Go to this page and download the library: Download sebbmeyer/php-microsoft-teams-connector 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/ */

    

sebbmeyer / php-microsoft-teams-connector example snippets


// create connector instance
$connector = new \Sebbmyr\Teams\TeamsConnector(<INCOMING_WEBHOOK_URL>);
// create card
$card  = new \Sebbmyr\Teams\Cards\SimpleCard(['title' => 'Simple card title', 'text' => 'Simple card text']);
// send card via connector
$connector->send($card);

// create a custom card
$card  = new \Sebbmyr\Teams\Cards\CustomCard('Package update', 'A custom card class was added to the package.');
// add information
$card->setColor('01BC36')
    ->addFactsText('Supported PHP versions',['<= 5.4.0','7.x'])
    ->addFactsText('Unsupported PHP versions',['Before Version 5.4'])
    ->addAction('Visit Github repository','https://github.com/sebbmeyer/php-microsoft-teams-connector')
    ->addFacts('Facts Section',['Fact Name 1' => 'Fact Value 1','Fact Name 2' => 'Fact Value 2']);

\\ Sebbmyr\LaravelTeams\Cards\ForgeCard.php
public function getMessage()
{
    return [
        "@type" => "MessageCard",
        "@context" => "http://schema.org/extensions",
        "summary" => "Forge Card",
        "themeColor" => ($this->data["status"] === 'success') ? self::STATUS_SUCCESS : self::STATUS_ERROR,
        "title" => "Forge deployment message",
        "sections" => [
            [
                "activityTitle" => "",
                "activitySubtitle" => "",
                "activityImage" => "",
                "facts" => [
                    [
                        "name" => "Server:",
                        "value" => $this->data["server"]['name']
                    ],
                    [
                        "name" => "Site",
                        "value" => "[". $this->data["site"]["name"] ."](http://". $this->data["site"]["name"] .")"
                    ],                        [
                        "name" => "Commit hash:",
                        "value" => "[". $this->data["commit_hash"] ."](". $this->data["commit_url"] .")"
                    ],
                    [
                        "name" => "Commit message",
                        "value" => $this->data["commit_message"]
                    ]
                ],
                "text" => ($this->data["status"] === 'success') ? $this->data["commit_author"] ." deployed some fresh code!" : "Something went wrong :/"
            ]
        ]
    ];
}

// create connector instance
$connector = new \Sebbmyr\Teams\TeamsConnector(<INCOMING_WEBHOOK_URL>);
// create data
$data = [
    "body" => [
        [
            "type" =>  "TextBlock",
            "text" =>  "Adaptive card test. For Samples and Templates, see https://adaptivecards.io/samples](https://adaptivecards.io/samples)",
        ],
    ],
];
// create card
$card  = new \Sebbmyr\Teams\Cards\Adaptive\BaseAdaptiveCard($data);
// send card via connector
$connector->send($card);

// create connector instance
$connector = new \Sebbmyr\Teams\TeamsConnector(<INCOMING_WEBHOOK_URL>);
// create data
$textBlockA = new  \Sebbmyr\Teams\Cards\Adaptive\Elements\TextBlock("Adaptive card");
$textBlockA->setColor( \Sebbmyr\Teams\Cards\Adaptive\Styles::COLORS_WARNING)
    ->setSize( \Sebbmyr\Teams\Cards\Adaptive\Styles::FONT_SIZE_LARGE)
;
$textBlockB = new  \Sebbmyr\Teams\Cards\Adaptive\Elements\TextBlock("Supported by composer package sebbmeyer/php-microsoft-teams-connector");
$textBlockB->setIsSubtle(true);
$image = new  \Sebbmyr\Teams\Cards\Adaptive\Elements\Image("https://adaptivecards.io/content/cats/1.png");
$image->setHorizontalAligment( \Sebbmyr\Teams\Cards\Adaptive\Styles::HORIZONTAL_ALIGNMENT_CENTER)
    ->setSize( \Sebbmyr\Teams\Cards\Adaptive\Styles::IMAGE_SIZE_MEDIUM)
;
$openUrl = new \Sebbmyr\Teams\Cards\Adaptive\Actions\OpenUrl
$openUrl = new \Sebbmyr\Teams\Cards\Adaptive\Actions\OpenUrl("https://github.com/sebbmeyer/php-microsoft-teams-connector");
    $openUrl->setTitle("Open Github");
// create card
$card = new \Sebbmyr\Teams\Cards\Adaptive\CustomAdaptiveCard();
$card->addElement($textBlockA)
    ->addElement($textBlockB)
    ->addElement($image)
    ->addAction($openUrl)
;
// send card via connector
$connector->send($card);

// create connector instance
$connector = new \Sebbmyr\Teams\TeamsConnector(<INCOMING_WEBHOOK_URL>);
// create card
$card = new \Sebbmyr\Teams\Cards\HeroCard();
$card->setTitle("Hero Card")
    ->setSubtitle("Featuring Deadpool")
    ->addImage("https://miro.medium.com/max/3840/1*0ubYRV_WNR9iYrzUAVINHw.jpeg")
    ->setText("Deadpool is a fictional character appearing in American comic books published by Marvel Comics. Created by writer Fabian Nicieza and artist/writer Rob Liefeld, the character first appeared in The New Mutants #98 (cover-dated February 1991). Initially Deadpool was depicted as a supervillain when he made his first appearance in The New Mutants and later in issues of X-Force, but later evolved into his more recognizable antiheroic persona. Deadpool, whose real name is Wade Winston Wilson, is a disfigured mercenary with the superhuman ability of an accelerated healing factor and physical prowess. The character is known as the \"Merc with a Mouth\" because of his tendency to talk and joke constantly, including breaking the fourth wall for humorous effect and running gags.")
    ->addButton("openUrl", "Wikipedia page", "https://en.wikipedia.org/wiki/Deadpool")
;
// send card via connector
$connector->send($card);