diff --git a/README.md b/README.md index dc540f3..4c408d2 100644 --- a/README.md +++ b/README.md @@ -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 >> \ No newline at end of file diff --git a/implementation.js b/implementation.js new file mode 100644 index 0000000..f321785 --- /dev/null +++ b/implementation.js @@ -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; + } +} \ No newline at end of file diff --git a/plugin.json b/plugin.json new file mode 100644 index 0000000..f21e5d7 --- /dev/null +++ b/plugin.json @@ -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 <>\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" +} \ No newline at end of file