-
Notifications
You must be signed in to change notification settings - Fork 399
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Kazuhiro Sera <seratch@gmail.com>
- Loading branch information
1 parent
e51960b
commit d3fe549
Showing
89 changed files
with
1,134 additions
and
1,648 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
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,28 @@ | ||
--- | ||
title: Listening to events | ||
lang: en | ||
slug: /concepts/event-listening | ||
--- | ||
|
||
You can listen to any [Events API event](https://api.slack.com/events) using the `event()` method after subscribing to it in your app configuration. This allows your app to take action when something happens in Slack, like a user reacting to a message or joining a channel. | ||
|
||
The `event()` method requires an `eventType` of type string. | ||
|
||
```javascript | ||
const welcomeChannelId = 'C12345'; | ||
|
||
// When a user joins the team, send a message in a predefined channel asking them to introduce themselves | ||
app.event('team_join', async ({ event, client, logger }) => { | ||
try { | ||
// Call chat.postMessage with the built-in client | ||
const result = await client.chat.postMessage({ | ||
channel: welcomeChannelId, | ||
text: `Welcome to the team, <@${event.user.id}>! 🎉 You can introduce yourself in this channel.` | ||
}); | ||
logger.info(result); | ||
} | ||
catch (error) { | ||
logger.error(error); | ||
} | ||
}); | ||
``` |
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,56 @@ | ||
--- | ||
title: Listening to messages | ||
lang: en | ||
slug: /concepts/message-listening | ||
--- | ||
|
||
To listen to messages that [your app has access to receive](https://api.slack.com/messaging/retrieving#permissions), you can use the `message()` method which filters out events that aren’t of type `message` .A `message()` listener is equivalent to `event('message')` | ||
|
||
The `message()` listener accepts an optional `pattern` parameter of type `string` or `RegExp` object which filters out any messages that don’t match the pattern. | ||
|
||
```javascript | ||
// This will match any message that contains 👋 | ||
app.message(':wave:', async ({ message, say }) => { | ||
// Handle only newly posted messages here | ||
if (message.subtype === undefined | ||
|| message.subtype === 'bot_message' | ||
|| message.subtype === 'file_share' | ||
|| message.subtype === 'thread_broadcast') { | ||
await say(`Hello, <@${message.user}>`); | ||
} | ||
}); | ||
``` | ||
|
||
## Using a RegExp pattern {#using-regexp} | ||
|
||
A RegExp pattern can be used instead of a string for more granular matching. | ||
|
||
All of the results of the RegExp match will be in `context.matches`. | ||
|
||
```javascript | ||
app.message(/^(hi|hello|hey).*/, async ({ context, say }) => { | ||
// RegExp matches are inside of context.matches | ||
const greeting = context.matches[0]; | ||
|
||
await say(`${greeting}, how are you?`); | ||
}); | ||
``` | ||
|
||
## Filtering on event subtypes {#filtering-event-subtypes} | ||
|
||
You can filter on subtypes of events by using the built-in `subtype()` middleware. Common message subtypes like `message_changed` and `message_replied` can be found [on the message event page](https://api.slack.com/events/message#message_subtypes). | ||
|
||
```javascript | ||
// Import subtype from the package | ||
const { App, subtype } = require('@slack/bolt'); | ||
|
||
// Matches all message changes from users | ||
app.message(subtype('message_changed'), ({ event, logger }) => { | ||
// This if statement is required in TypeScript code | ||
if (event.subtype === 'message_changed' | ||
&& !event.message.subtype | ||
&& !event.previous_message.subtype) { | ||
logger.info(`The user ${event.message.user} changed their message from ${event.previous_message.text} to ${event.message.text}`); | ||
} | ||
}); | ||
``` |
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions
4
docs/content/basic/options.md → docs/content/concepts/select-menu-options.md
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
2 changes: 1 addition & 1 deletion
2
docs/content/basic/shortcuts.md → docs/content/concepts/shortcuts.md
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
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
docs/content/basic/updating-pushing-views.md → ...ontent/concepts/updating-pushing-views.md
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
File renamed without changes.
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
Oops, something went wrong.