Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions examples/slack-update-and-delete/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
SLACK_ACCESS_TOKEN=
SLACK_SIGNING_SECRET=
51 changes: 51 additions & 0 deletions examples/slack-update-and-delete/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Slack Update and Delete

## Install and Run

Download this example or clone [bottender](https://github.com/Yoctol/bottender).

```sh
curl https://codeload.github.com/Yoctol/bottender/tar.gz/master | tar -xz --strip=2 bottender-master/examples/slack-update-and-delete
cd slack-update-and-delete
```

Install dependencies:

```sh
npm install
```

You must fill `SLACK_ACCESS_TOKEN` and `SLACK_SIGNING_SECRET` in your `.env` file.

If you are not familiar with Slack Bot, you may refer to Bottender's doc, [Slack Setup](https://bottender.js.org/docs/channel-slack-setup), to find detailed instructions.

After that, you can run the bot with this npm script:

```sh
npm run dev
```

This command starts a server listening at `http://localhost:5000` for bot development.

If you successfully start the server, you get a webhook URL in the format of `https://xxxxxxxx.ngrok.io/webhooks/slack` from your terminal.

## Set Webhook

To set the webhook, go to [Slack Developer Console](https://api.slack.com/apps) / [YourApp] / Event Subscriptions, and use the webhook URL you got from running `npm run dev` to edit Request URL for your bot.

## Idea of This Example

This example is a bot running on [Slack](https://slack.com/).

This example contains the following topics:

- update the message sent by bot
- delete the message sent by bot

For more information, check our [Slack guides](https://bottender.js.org/docs/en/channel-slack-sending-messages#updating-messages).

## Related Examples

- [slack-hello-world](../slack-hello-world)
- [slack-interactive-message](../slack-interactive-message)
- [slack-slash-command](../slack-slash-command)
10 changes: 10 additions & 0 deletions examples/slack-update-and-delete/bottender.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module.exports = {
channels: {
slack: {
enabled: true,
path: '/webhooks/slack',
accessToken: process.env.SLACK_ACCESS_TOKEN,
signingSecret: process.env.SLACK_SIGNING_SECRET,
},
},
};
24 changes: 24 additions & 0 deletions examples/slack-update-and-delete/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module.exports = async function App(context) {
if (
context.event.rawEvent.subtype === 'message_changed' ||
context.event.rawEvent.subtype === 'message_deleted'
) {
return;
}

const response = await context.chat.postMessage({
text: 'This is a normal message by chat.postMessage.',
});

const { ts, channel } = response;

await context.chat.update({
text: 'Message updated.',
ts,
channel,
});

await context.chat.delete({
ts,
});
};
9 changes: 9 additions & 0 deletions examples/slack-update-and-delete/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"scripts": {
"dev": "bottender dev",
"start": "bottender start"
},
"dependencies": {
"bottender": "latest"
}
}