-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
“Dat
committed
Sep 27, 2024
1 parent
867c335
commit c7a436b
Showing
3 changed files
with
87 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,13 @@ | ||
# slack-webhook-message-notifier | ||
# Slack Webhook Message Notifier | ||
A plugin that sends messages to a Slack channel using an incoming webhook. | ||
|
||
❗**Important Notes**: | ||
- This plugin requires a webhook URL from Slack. [Learn how to set up an incoming webhook here](https://api.slack.com/messaging/webhooks) | ||
- This plugin can only send messages to a single pre-configured channel via webhook. | ||
|
||
### Example Usage: | ||
> Send a summary of this document to my Slack channel. | ||
<< Your document content >> | ||
> Send a summary of this document to my Slack channel. | ||
<< Attach a document file >> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
const GENERAL_ERROR_MESSAGE = "I cannot do that..." | ||
async function send_message_to_slack_channel_with_webhook(params, userSettings) { | ||
const { message } = params; | ||
const { slackWebhookUrl } = userSettings; | ||
if (!slackWebhookUrl) { | ||
return GENERAL_ERROR_MESSAGE; | ||
} | ||
|
||
const payload = { | ||
blocks: [ | ||
{ | ||
type: 'section', | ||
text: { | ||
type: 'plain_text', | ||
text: message, | ||
emoji: true, | ||
}, | ||
}, | ||
], | ||
}; | ||
|
||
try { | ||
const response = await fetch(slackWebhookUrl, { | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/x-www-form-urlencoded", | ||
}, | ||
body: JSON.stringify(payload), | ||
}); | ||
|
||
if (response.ok) { | ||
return "Message has been sent to Slack."; | ||
} else { | ||
return GENERAL_ERROR_MESSAGE; | ||
} | ||
} catch (error) { | ||
console.error("Error sending message to Slack:", error); | ||
return GENERAL_ERROR_MESSAGE; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
{ | ||
"uuid": "9e48f0eb-6b09-44e5-80cd-eb9955ede2eb", | ||
"id": "send_message_to_slack_channel_with_webhook", | ||
"emoji": "🧩", | ||
"title": "Slack Webhook Message Notifier", | ||
"overviewMarkdown": "# Slack Webhook Message Notifier\nA plugin that sends messages to a Slack channel using an incoming webhook.\n\n❗**Important Notes**:\n- This plugin requires a webhook URL from Slack. [Learn how to set up an incoming webhook here](https://api.slack.com/messaging/webhooks)\n- This plugin can only send messages to a single pre-configured channel via webhook.\n\n### Example Usage:\n> Send a summary of this document to my Slack channel.\n <<Your document content >>\n\n> Send a summary of this document to my Slack channel.\n << Attach a document file >>", | ||
"openaiSpec": { | ||
"name": "send_message_to_slack_channel_with_webhook", | ||
"description": "This function sends a message to a Slack channel via an incoming webhook", | ||
"parameters": { | ||
"type": "object", | ||
"properties": { | ||
"message": { | ||
"type": "string", | ||
"description": "This parameter represents the message that a user wants to send to the Slack channel" | ||
} | ||
}, | ||
"required": [ | ||
"message" | ||
] | ||
} | ||
}, | ||
"iconURL": "https://upload.wikimedia.org/wikipedia/commons/d/d5/Slack_icon_2019.svg", | ||
"userSettings": [ | ||
{ | ||
"name": "slackWebhookUrl", | ||
"label": "Slack Webhook URL", | ||
"placeholder": "https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX", | ||
"description": "Follow the steps to get your Slack Webhook URL at https://api.slack.com/messaging/webhooks.", | ||
"required": true | ||
} | ||
], | ||
"implementationType": "javascript", | ||
"outputType": "respond_to_ai" | ||
} |