Skip to content

[Notifier] Documentation for Microsoft Teams Options #15288

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added _images/notifier/microsoft_teams/message-card.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added _images/notifier/microsoft_teams/message.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
93 changes: 93 additions & 0 deletions notifier/chatters.rst
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,99 @@ to add `message options`_::

$chatter->send($chatMessage);

Adding text to a Microsoft Teams Message
----------------------------------------

With a Microsoft Teams, you can use the simple ChatMessage::

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:

.. image:: /_images/notifier/microsoft_teams/message.png
:align: center

Adding Interactions to a Microsoft Teams Message
------------------------------------------------

With a Microsoft Teams Message, you can use the
:class:`Symfony\\Component\\Notifier\\Bridge\\MicrosoftTeams\\MicrosoftTeamsOptions` class
to add `MessageCard options`_::

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('');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the first argument really be empty?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new ChatMessage('') requires a subject string argument, if this argument is given, then ->text('Text') should be skipped while setting new MicrosoftTeamsOptions(). In otherw words new ChatMessage('') and ->text('Text') are equivalents. In my example I used second one to set the text.


// 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:

.. image:: /_images/notifier/microsoft_teams/message-card.png
:align: center

.. versionadded:: 5.3

Options for Microsoft Teams were introduced in Symfony 5.3.

.. _`Block elements`: https://api.slack.com/reference/block-kit/block-elements
.. _`Embed elements`: https://discord.com/developers/docs/resources/webhook
.. _`message options`: https://core.telegram.org/bots/api
.. _`MessageCard options`: https://docs.microsoft.com/en-us/outlook/actionable-messages/message-card-reference