From 3947e64208ba01ef5c33eda41473dad5c28f79ee Mon Sep 17 00:00:00 2001 From: JessHerbert <39200632+JessicaHerbert@users.noreply.github.com> Date: Fri, 5 Sep 2025 10:05:21 -0400 Subject: [PATCH 1/3] update readme for slack tasks --- .../task_webhook_slack/CANVAS_MANIFEST.json | 29 +++++++ extensions/task_webhook_slack/README.md | 82 +++++++++++++++++++ .../task_webhook_slack/protocols/__init__.py | 0 .../protocols/task_webhook_notification.py | 77 +++++++++++++++++ 4 files changed, 188 insertions(+) create mode 100644 extensions/task_webhook_slack/CANVAS_MANIFEST.json create mode 100644 extensions/task_webhook_slack/README.md create mode 100644 extensions/task_webhook_slack/protocols/__init__.py create mode 100644 extensions/task_webhook_slack/protocols/task_webhook_notification.py diff --git a/extensions/task_webhook_slack/CANVAS_MANIFEST.json b/extensions/task_webhook_slack/CANVAS_MANIFEST.json new file mode 100644 index 00000000..a9b0ab47 --- /dev/null +++ b/extensions/task_webhook_slack/CANVAS_MANIFEST.json @@ -0,0 +1,29 @@ +{ + "sdk_version": "0.1.4", + "plugin_version": "0.0.1", + "name": "task_webhook_notification", + "description": "Listens to a task created/updated and sends a payload to a webhook", + "components": { + "protocols": [ + { + "class": "task_webhook_notification.protocols.task_webhook_notification:TaskWebhookNotificationProtocol", + "description": "Listens to a task created/updated and sends a payload to a webhook", + "data_access": { + "event": "", + "read": [], + "write": [] + } + } + ], + "commands": [], + "content": [], + "effects": [], + "views": [] + }, + "secrets": ["WEBHOOK_NOTIFICATION_URL", "AUTH_TOKEN"], + "tags": {}, + "references": [], + "license": "", + "diagram": false, + "readme": "./README.md" +} diff --git a/extensions/task_webhook_slack/README.md b/extensions/task_webhook_slack/README.md new file mode 100644 index 00000000..cd9c1ec7 --- /dev/null +++ b/extensions/task_webhook_slack/README.md @@ -0,0 +1,82 @@ +# Task Webhook Slack Integration + +![Slack Logo](https://a.slack-edge.com/80588/marketing/img/icons/icon_slack_hash_colored.png) + +## Description + +This extension integrates Canvas task management with Slack notifications. When a task in Canvas is created or updated, it automatically sends a formatted message to a Slack channel via webhook, keeping your team informed in real-time. + +## How It Works + +When a task event occurs in Canvas, this extension: +1. Captures the task details and associated patient/assignee information +2. Formats the data into a Slack-friendly payload +3. Sends the notification to your configured Slack webhook URL + +## Slack Setup + +### 1. Create a Slack App and Webhook + +1. Go to [api.slack.com/apps](https://api.slack.com/apps) and create a new app +2. Choose "From scratch" and give it a name like "Canvas Task Notifications" +3. Select your workspace +4. Go to "Incoming Webhooks" and activate them +5. Click "Add New Webhook to Workspace" +6. Choose the channel where you want task notifications +7. Copy the webhook URL (it will look like: `https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX`) + +### 2. Configure Canvas Extension + +Set these plugin secrets in your Canvas environment: + +- `WEBHOOK_NOTIFICATION_URL`: Your Slack webhook URL +- `AUTH_TOKEN`: Leave empty (Slack webhooks don't require bearer tokens) + +## Payload Structure + +The webhook sends the following data to Slack: + +```json +{ + "task_id": "12345", + "event": "created", // or "updated" + "title": "Follow up with patient", + "due_date": "2024-01-15T10:00:00Z", + "patient": { + "id": "67890", + "first_name": "John", + "last_name": "Doe", + "birth_date": "1980-05-15", + "sex_at_birth": "Male" + }, + "creator": { + "id": "11111", + "first_name": "Dr. Jane", + "last_name": "Smith" + }, + "assignee": { + "staff": { + "id": "22222", + "first_name": "Nurse", + "last_name": "Johnson" + }, + "team": null + } +} +``` + +## Example Slack Message + +When a task is created, you'll see a message like: + +> **📋 New Task Created** +> +> **Title:** Follow up with patient +> **Due:** January 15, 2024 at 10:00 AM +> **Patient:** John Doe (DOB: 05/15/1980, Male) +> **Created by:** Dr. Jane Smith +> **Assigned to:** Nurse Johnson + +## Customization + +You can customize the webhook payload format by modifying the `task_webhook_notification.py` file to match your specific Slack integration needs. diff --git a/extensions/task_webhook_slack/protocols/__init__.py b/extensions/task_webhook_slack/protocols/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/extensions/task_webhook_slack/protocols/task_webhook_notification.py b/extensions/task_webhook_slack/protocols/task_webhook_notification.py new file mode 100644 index 00000000..0f8081da --- /dev/null +++ b/extensions/task_webhook_slack/protocols/task_webhook_notification.py @@ -0,0 +1,77 @@ +from canvas_sdk.events import EventType +from canvas_sdk.protocols import BaseProtocol +from canvas_sdk.utils import Http +from canvas_sdk.v1.data.task import Task + +from logger import log + + +class TaskWebhookNotificationProtocol(BaseProtocol): + """ + When a task is created or updated, hit a webhook + """ + + RESPONDS_TO = [ + EventType.Name(EventType.TASK_CREATED), + EventType.Name(EventType.TASK_UPDATED), + ] + + def compute(self): + """ + Notify our server of tasks as they are created. + """ + url = self.secrets["WEBHOOK_NOTIFICATION_URL"] + auth_token = self.secrets["AUTH_TOKEN"] + headers = {"Authorization": f"Bearer {auth_token}"} + + verb = 'created' if self.event.type == EventType.TASK_CREATED else 'updated' + + task = Task.objects.select_related("patient").select_related("creator").get(id=self.target) + + patient_details = None + if task.patient: + patient_details = { + "id": task.patient.id, + "first_name": task.patient.first_name, + "last_name": task.patient.last_name, + "birth_date": task.patient.birth_date.isoformat(), + "sex_at_birth": task.patient.get_sex_at_birth_display(), + } + + staff_assignee_details = None + if task.assignee: + staff_assignee_details = { + "id": task.assignee.id, + "first_name": task.assignee.first_name, + "last_name": task.assignee.last_name, + } + + payload = { + "task_id": self.target, + "event": verb, + "title": task.title, + "due_date": task.due.isoformat(), + "patient": patient_details, + "creator": { + "id": task.creator.id, + "first_name": task.creator.first_name, + "last_name": task.creator.last_name, + }, + "assignee": { + "staff": staff_assignee_details, + # populate when team is available through the data module; + "team": None + } + } + + http = Http() + response = http.post(url, json=payload, headers=headers) + + event_name = EventType.Name(self.event.type) + + if response.ok: + log.info(f"Successfully notified API of {event_name} for task ID {task.id}") + else: + log.info(f"Notification of {event_name} for task ID {task.id} unsuccessful. =[") + + return [] From 42cec8c03c2d2faadc24bba87a1c4e06153cce98 Mon Sep 17 00:00:00 2001 From: JessHerbert <39200632+JessicaHerbert@users.noreply.github.com> Date: Fri, 5 Sep 2025 10:19:37 -0400 Subject: [PATCH 2/3] formatting update --- extensions/task_webhook_slack/README.md | 47 ++++++++++++++++--------- 1 file changed, 31 insertions(+), 16 deletions(-) diff --git a/extensions/task_webhook_slack/README.md b/extensions/task_webhook_slack/README.md index cd9c1ec7..eee9ac79 100644 --- a/extensions/task_webhook_slack/README.md +++ b/extensions/task_webhook_slack/README.md @@ -1,21 +1,36 @@ # Task Webhook Slack Integration -![Slack Logo](https://a.slack-edge.com/80588/marketing/img/icons/icon_slack_hash_colored.png) +image + ## Description +Make integrations more efficient with webhooks. Webhooks are used to notify an application when an event occurs in another system, acting as a real-time communication channel and "push" information as soon as an event happens. + +When a task in Canvas is created or updated, send a webhook playload to an endpoint of your choice. + +The Canvas payload includes the following: -This extension integrates Canvas task management with Slack notifications. When a task in Canvas is created or updated, it automatically sends a formatted message to a Slack channel via webhook, keeping your team informed in real-time. +Task: ID, event (updated, created), title, due date +Patient: ID, first name, last name, date of birth, sex at birth +Assignee: ID, first name, last name, team (if applicable) +Task creator, ID, first name, last name +Customize the event trigger and payload to fit your needs. -## How It Works +## Example +An example implemenation integrates Canvas task management with Slack notifications. When a task in Canvas is created or updated, it automatically sends a formatted message to a Slack channel via webhook, keeping your team informed in real-time. + + +### How It Works When a task event occurs in Canvas, this extension: 1. Captures the task details and associated patient/assignee information 2. Formats the data into a Slack-friendly payload 3. Sends the notification to your configured Slack webhook URL -## Slack Setup +### Slack Setup -### 1. Create a Slack App and Webhook +#### 1. Create a Slack App and Webhook +Reference: https://docs.slack.dev/messaging/sending-messages-using-incoming-webhooks/ 1. Go to [api.slack.com/apps](https://api.slack.com/apps) and create a new app 2. Choose "From scratch" and give it a name like "Canvas Task Notifications" @@ -25,14 +40,14 @@ When a task event occurs in Canvas, this extension: 6. Choose the channel where you want task notifications 7. Copy the webhook URL (it will look like: `https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX`) -### 2. Configure Canvas Extension +#### 2. Configure Canvas Extension Set these plugin secrets in your Canvas environment: - `WEBHOOK_NOTIFICATION_URL`: Your Slack webhook URL - `AUTH_TOKEN`: Leave empty (Slack webhooks don't require bearer tokens) -## Payload Structure +### Payload Structure The webhook sends the following data to Slack: @@ -65,18 +80,18 @@ The webhook sends the following data to Slack: } ``` -## Example Slack Message +### Example Slack Message When a task is created, you'll see a message like: -> **📋 New Task Created** -> -> **Title:** Follow up with patient -> **Due:** January 15, 2024 at 10:00 AM -> **Patient:** John Doe (DOB: 05/15/1980, Male) -> **Created by:** Dr. Jane Smith -> **Assigned to:** Nurse Johnson +**📋 New Task Created** + +- **Title:** Follow up with patient +- **Due:** January 15, 2024 at 10:00 AM +- **Patient:** John Doe (DOB: 05/15/1980, Male) +- **Created by:** Dr. Jane Smith +- **Assigned to:** Nurse Johnson ## Customization -You can customize the webhook payload format by modifying the `task_webhook_notification.py` file to match your specific Slack integration needs. +You can customize the webhook payload format by modifying the `task_webhook_notification.py` file to match your specific Slack integration needs. \ No newline at end of file From 39c9f05b6a782c10a597755a52c2da63a1601785 Mon Sep 17 00:00:00 2001 From: JessHerbert <39200632+JessicaHerbert@users.noreply.github.com> Date: Fri, 5 Sep 2025 10:25:27 -0400 Subject: [PATCH 3/3] Update README.md more formatting update --- extensions/task_webhook_slack/README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/extensions/task_webhook_slack/README.md b/extensions/task_webhook_slack/README.md index eee9ac79..2f801e5a 100644 --- a/extensions/task_webhook_slack/README.md +++ b/extensions/task_webhook_slack/README.md @@ -10,11 +10,11 @@ When a task in Canvas is created or updated, send a webhook playload to an endpo The Canvas payload includes the following: -Task: ID, event (updated, created), title, due date -Patient: ID, first name, last name, date of birth, sex at birth -Assignee: ID, first name, last name, team (if applicable) -Task creator, ID, first name, last name -Customize the event trigger and payload to fit your needs. +- Task: ID, event (updated, created), title, due date +- Patient: ID, first name, last name, date of birth, sex at birth +- Assignee: ID, first name, last name, team (if applicable) +- Task creator, ID, first name, last name +- Customize the event trigger and payload to fit your needs. ## Example An example implemenation integrates Canvas task management with Slack notifications. When a task in Canvas is created or updated, it automatically sends a formatted message to a Slack channel via webhook, keeping your team informed in real-time. @@ -94,4 +94,4 @@ When a task is created, you'll see a message like: ## Customization -You can customize the webhook payload format by modifying the `task_webhook_notification.py` file to match your specific Slack integration needs. \ No newline at end of file +You can customize the webhook payload format by modifying the `task_webhook_notification.py` file to match your specific Slack integration needs.