Microsoft Teams Notifier
Warning: You are browsing the documentation for Symfony 6.0, which is no longer maintained.
Consider upgrading your projects to Symfony 7.1.
Microsoft Teams Notifier
The Microsoft Teams Notifier package allows to use Microsoft Teams via the Symfony Notifier component. Read the main Notifier docs to learn about installing and configuring that component.
Adding text to a Message
With a Microsoft Teams, you can use the ChatMessage class:
1 2 3 4 5
use Symfony\Component\Notifier\Bridge\MicrosoftTeams\MicrosoftTeamsTransport;
use Symfony\Component\Notifier\Message\ChatMessage;
$chatMessage = (new ChatMessage('Contribute To Symfony'))->transport('microsoftteams');
$chatter->send($chatMessage);
The result will be something like:
Adding Interactions to a Message
With a Microsoft Teams Message, you can use the MicrosoftTeamsOptions class to add MessageCard options:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
use Symfony\Component\Notifier\Bridge\MicrosoftTeams\Action\ActionCard;
use Symfony\Component\Notifier\Bridge\MicrosoftTeams\Action\HttpPostAction;
use Symfony\Component\Notifier\Bridge\MicrosoftTeams\Action\Input\DateInput;
use Symfony\Component\Notifier\Bridge\MicrosoftTeams\Action\Input\TextInput;
use Symfony\Component\Notifier\Bridge\MicrosoftTeams\MicrosoftTeamsOptions;
use Symfony\Component\Notifier\Bridge\MicrosoftTeams\MicrosoftTeamsTransport;
use Symfony\Component\Notifier\Bridge\MicrosoftTeams\Section\Field\Fact;
use Symfony\Component\Notifier\Bridge\MicrosoftTeams\Section\Section;
use Symfony\Component\Notifier\Message\ChatMessage;
$chatMessage = new ChatMessage('');
// Action elements
$input = new TextInput();
$input->id('input_title');
$input->isMultiline(true)->maxLength(5)->title('In a few words, why would you like to participate?');
$inputDate = new DateInput();
$inputDate->title('Proposed date')->id('input_date');
// Create Microsoft Teams MessageCard
$microsoftTeamsOptions = (new MicrosoftTeamsOptions())
->title('Symfony Online Meeting')
->text('Symfony Online Meeting are the events where the best developers meet to share experiences...')
->summary('Summary')
->themeColor('#F4D35E')
->section((new Section())
->title('Talk about Symfony 5.3 - would you like to join? Please give a shout!')
->fact((new Fact())
->name('Presenter')
->value('Fabien Potencier')
)
->fact((new Fact())
->name('Speaker')
->value('Patricia Smith')
)
->fact((new Fact())
->name('Duration')
->value('90 min')
)
->fact((new Fact())
->name('Date')
->value('TBA')
)
)
->action((new ActionCard())
->name('ActionCard')
->input($input)
->input($inputDate)
->action((new HttpPostAction())
->name('Add comment')
->target('http://target')
)
)
;
// Add the custom options to the chat message and send the message
$chatMessage->options($microsoftTeamsOptions);
$chatter->send($chatMessage);
The result will be something like:
This work, including the code samples, is licensed under a
Creative Commons BY-SA 3.0 license.