Skip to content

Commit

Permalink
Initial Setup
Browse files Browse the repository at this point in the history
  • Loading branch information
“Dat committed Sep 27, 2024
1 parent 867c335 commit c7a436b
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 1 deletion.
13 changes: 12 additions & 1 deletion README.md
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 >>
40 changes: 40 additions & 0 deletions implementation.js
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;
}
}
35 changes: 35 additions & 0 deletions plugin.json
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"
}

0 comments on commit c7a436b

Please sign in to comment.