Skip to content

Commit

Permalink
feat: add slack blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
scopsy committed Jul 24, 2024
1 parent 023100b commit adc463b
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 13 deletions.
13 changes: 13 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
// For more information, visit: https://go.microsoft.com/fwlink/?LinkId=733558
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"command": "mintlify dev",
"isBackground": true,
"label": "DOCS"
}
]
}

51 changes: 38 additions & 13 deletions integrations/providers/chat/slack.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,18 @@ This guide will walk you through the steps needed to obtain the `webhookUrl` t

We will provide the basic flow that the user needs to perform, to successfully send notifications via the Slack integration.

<Note>
We've a [dedicated guide](/guides/slack-guide) on integrating Novu in a Slack
app.
</Note>

### Creating application
## Creating application

This step is optional, if you already have a Slack application you can reuse it.

1. Go to Slack's developer dashboard https://api.slack.com/apps.
2. Create a new application.

### Integrating Novu with Slack
## Integrating Novu with Slack

There are two ways to integrate Novu with Slack - Novu Managed (recommended) and manually managed. Let’s look at both of them in detail:

### 1. Novu Managed (Recommended)
### Novu Managed (Recommended)

If you use this approach, then Novu will manage the OAuth flow and store the credentials

Expand Down Expand Up @@ -89,7 +84,7 @@ https://api.novu.co/v1/subscribers/<SUBSCRIBER_ID>/credentials/slack/oauth?envir
integrating Novu in a Slack app for more.
</Note>

### 2. Manually managed
### Manually managed

To use the manually managed option, you need to generate a `webhookUrl` and plug it into your backend.

Expand All @@ -111,6 +106,37 @@ To use the manually managed option, you need to generate a `webhookUrl` and plug
</Frame>
5. Now, you need to save the `webhookUrl` on the relevant subscriber entity in Novu. Here's an example to do the same using our Node SDK:

## Writing Slack content (Blocks API)

Novu Framework supports using [blocks](https://api.slack.com/block-kit) as part of the delivered messages using the provider overrides of the `chat` channel:

You can use the [Blocks Playground](https://app.slack.com/block-kit-builder/T02QYEPHZMM#%7B%22blocks%22:%5B%7B%22type%22:%22section%22,%22text%22:%7B%22type%22:%22mrkdwn%22,%22text%22:%22Hello,%20Assistant%20to%20the%20Regional%20Manager%20Dwight!%20*Michael%20Scott*%20wants%20to%20know%20where%20you'd%20like%20to%20take%20the%20Paper%20Company%20investors%20to%20dinner%20tonight.%5Cn%5Cn%20*Please%20select%20a%20restaurant:*%22%7D%7D,%7B%22type%22:%22divider%22%7D,%7B%22type%22:%22section%22,%22text%22:%7B%22type%22:%22mrkdwn%22,%22text%22:%22*Farmhouse%20Thai%20Cuisine*%5Cn:star::star::star::star:%201528%20reviews%5Cn%20They%20do%20have%20some%20vegan%20options,%20like%20the%20roti%20and%20curry,%20plus%20they%20have%20a%20ton%20of%20salad%20stuff%20and%20noodles%20can%20be%20ordered%20without%20meat!!%20They%20have%20something%20for%20everyone%20here%22%7D,%22accessory%22:%7B%22type%22:%22image%22,%22image_url%22:%22https://s3-media3.fl.yelpcdn.com/bphoto/c7ed05m9lC2EmA3Aruue7A/o.jpg%22,%22alt_text%22:%22alt%20text%20for%20image%22%7D%7D,%7B%22type%22:%22section%22,%22text%22:%7B%22type%22:%22mrkdwn%22,%22text%22:%22*Kin%20Khao*%5Cn:star::star::star::star:%201638%20reviews%5Cn%20The%20sticky%20rice%20also%20goes%20wonderfully%20with%20the%20caramelized%20pork%20belly,%20which%20is%20absolutely%20melt-in-your-mouth%20and%20so%20soft.%22%7D,%22accessory%22:%7B%22type%22:%22image%22,%22image_url%22:%22https://s3-media2.fl.yelpcdn.com/bphoto/korel-1YjNtFtJlMTaC26A/o.jpg%22,%22alt_text%22:%22alt%20text%20for%20image%22%7D%7D,%7B%22type%22:%22section%22,%22text%22:%7B%22type%22:%22mrkdwn%22,%22text%22:%22*Ler%20Ros*%5Cn:star::star::star::star:%202082%20reviews%5Cn%20I%20would%20really%20recommend%20the%20%20Yum%20Koh%20Moo%20Yang%20-%20Spicy%20lime%20dressing%20and%20roasted%20quick%20marinated%20pork%20shoulder,%20basil%20leaves,%20chili%20&%20rice%20powder.%22%7D,%22accessory%22:%7B%22type%22:%22image%22,%22image_url%22:%22https://s3-media2.fl.yelpcdn.com/bphoto/DawwNigKJ2ckPeDeDM7jAg/o.jpg%22,%22alt_text%22:%22alt%20text%20for%20image%22%7D%7D,%7B%22type%22:%22divider%22%7D,%7B%22type%22:%22actions%22,%22elements%22:%5B%7B%22type%22:%22button%22,%22text%22:%7B%22type%22:%22plain_text%22,%22text%22:%22Farmhouse%22,%22emoji%22:true%7D,%22value%22:%22click_me_123%22%7D,%7B%22type%22:%22button%22,%22text%22:%7B%22type%22:%22plain_text%22,%22text%22:%22Kin%20Khao%22,%22emoji%22:true%7D,%22value%22:%22click_me_123%22,%22url%22:%22https://google.com%22%7D,%7B%22type%22:%22button%22,%22text%22:%7B%22type%22:%22plain_text%22,%22text%22:%22Ler%20Ros%22,%22emoji%22:true%7D,%22value%22:%22click_me_123%22,%22url%22:%22https://google.com%22%7D%5D%7D%5D%7D) from Slack to learn more about the diffrent blocks available.

```typescript
await step.chat('send-chat', async () => {
return {
// This will be used as a fallback for the chat provider if other than Slack provider is used
body: 'A new post has been created',
};
}, {
providers: {
slack: async ({ inputs }) => ({
text: 'A new post has been created',
blocks: [
{
type: 'section',
text: {
type: 'mrkdwn',
text: 'A new post has been created',
},
},
],
}),
}
});
```


## Update credential webhookUrl

<Tabs>
Expand All @@ -124,10 +150,10 @@ import {
const novu = new Novu("<NOVU_API_KEY>");

await novu.subscribers.setCredentials('subscriberId', ChatProviderIdEnum.Slack, {
webhookUrl: "<WEBHOOK_URL>",
webhookUrl: "<WEBHOOK_URL>",
});

````
```
</Tab>
<Tab title="cURL">
```bash
Expand All @@ -142,8 +168,7 @@ curl -L -X PUT 'https://api.novu.co/v1/subscribers/<SUBSCRIBER_ID>/credentials'
},
"integrationIdentifier": "slack-MnGLxp8uy"
}'
````
```
</Tab>
</Tabs>

Expand Down

0 comments on commit adc463b

Please sign in to comment.