A worker that consume messages from the queue and notifies Slack.
- Create a file named .dev.vars in the project root directory.
- Write the following key-value pairs in the .dev.vars file:
SLACK_TOKEN=<Your_SLACK_TOKEN>
Replace
- '<Your_Slack_Bearer_Token>' with the bearer token for the Slack file upload API
Run the following commands to add your secrets to the Workers configuration:
secret
wrangler secret put SLACK_TOKEN
queues
wrangler queues create slackqueue
After you've added the secrets, deploy the Worker with the following command:
wrangler deploy
Add the following to your wrangler.toml
[[queues.producers]]
queue = "slackqueue"
binding = "SLACK_NOTIFIER"
Add the following to your worker script
export interface Env {
SLACK_NOTIFIER: Queue;
}
...
await env.SLACK_NOTIFIER.send({
type: "chat.postMessage",
body: {
channel: "your channel id"
text: "Hello, world!", // or blocks
},
});