โ All articles
Communication
Teams Chat Bot & Notifications Module
Create outbound triggers from Drupal events, inbound slash commands via webhook, and adaptive card templates for rich, branded messages in Microsoft Teams.
Published January 25, 2024
drupalmicrosoft-teamsnotificationschatbotadaptive-cardscollaborationwebhooks
Overview
The Teams Chat Bot & Notifications Module transforms how your organization communicates by bridging Drupal content workflows with Microsoft Teams. This integration enables automated notifications for content changes, interactive bot commands, and rich adaptive card messages that maintain your brand identity.
Features
- Automated notifications for Drupal events
- Inbound webhook support for slash commands
- Rich adaptive card templates
- Two-way communication between platforms
- Customizable notification rules
- Bot framework integration
- Team and channel targeting
- Message threading and replies
Technical Details
Technologies: Microsoft Teams Bot Framework, Microsoft Graph API, Adaptive Cards, Drupal Event System, Drupal Rules module, Webhooks
Requirements:
- Drupal 9.x or 10.x
- Microsoft Teams subscription
- Azure Bot Service registration
- Bot Framework SDK
- Drupal Rules or custom event subscribers
- HTTPS endpoint for webhooks
API Endpoints:
Send message: POST /teams/{team-id}/channels/{channel-id}/messages
Reply to message: POST /teams/{team-id}/channels/{channel-id}/messages/{message-id}/replies
Incoming webhook: POST {webhook-url}
Activity feed: POST /teams/{team-id}/sendActivityNotification
Implementation
- Register bot in Azure Bot Service
- Create Teams app manifest and install bot
- Implement bot message handler in Drupal
- Create adaptive card templates for notifications
- Set up Drupal event subscribers for triggers
- Configure webhook endpoints for inbound commands
- Implement slash command parsing
- Add message routing and channel management
- Create admin UI for notification rules
- Test bot interactions and error handling
<?php
// Example: Drupal event subscriber for Teams notifications
namespace Drupal\teams_integration\EventSubscriber;
use Drupal\Core\Entity\EntityInterface;
use Drupal\node\Event\NodeEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class TeamsNotificationSubscriber implements EventSubscriberInterface {
protected $teamsClient;
public function __construct($teams_client) {
$this->teamsClient = $teams_client;
}
public static function getSubscribedEvents() {
return [
'node.published' => 'onNodePublished',
'node.updated' => 'onNodeUpdated',
];
}
public function onNodePublished(NodeEvent $event) {
$node = $event->getNode();
// Create adaptive card
$card = [
'type' => 'message',
'attachments' => [[
'contentType' => 'application/vnd.microsoft.card.adaptive',
'content' => [
'type' => 'AdaptiveCard',
'body' => [
[
'type' => 'TextBlock',
'size' => 'Large',
'weight' => 'Bolder',
'text' => '๐ New Content Published',
],
[
'type' => 'TextBlock',
'text' => $node->getTitle(),
'wrap' => true,
],
[
'type' => 'TextBlock',
'text' => $node->get('body')->summary,
'isSubtle' => true,
'wrap' => true,
],
],
'actions' => [[
'type' => 'Action.OpenUrl',
'title' => 'View Article',
'url' => $node->toUrl('canonical', ['absolute' => TRUE])->toString(),
]],
],
]],
];
// Send to configured Teams channel
$this->teamsClient->sendMessage($card);
}
}
Use Cases
- Content approval workflows with team notifications
- Breaking news alerts to editorial teams
- Form submission notifications to support teams
- System status updates and alerts
- Collaborative content review processes
Benefits
- Real-time notifications in Teams workspace
- Reduced email overload for team communications
- Rich, branded message formatting
- Interactive elements for quick actions
- Centralized communication in Teams
- Improved response times for urgent updates
- Audit trail of notifications and responses