How to build a knowledge system with Slack and Notion
Tags: tutorial, javascript, webdev
Published: 2022-04-16 10:53:10

Have you ever felt like managing information flows more efficiently if you usually use Slack?

I want to share tips to manage information by Slack and Notion in this article.

{% embed https://www.youtube.com/watch?v=TXE3GPRgjCs %}

## Knowledge system by Slack and Notion
You need to follow the below prerequisite before you start this tutorial.

- Slack paid plan
- Slack account
- Notion account
- Google account
- Google sheets

We actually need Google sheets to post messages to Notion from Slack.

### Settings of Notion

Create a table to stock information. 

- Question: title
- Answer: rich_text
- URL: url
- Tags: multi_select

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/j0egar9qxa511td1ne5f.png)

Get a database's ID in Notion.
[📖 Lean more Notion databases](https://developers.notion.com/docs/working-with-databases)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2w8aya39dsx95aez3y0g.png)

Use `Copy link to view` from the menu.

```
https://www.notion.so/{workspace_name}/{database_id}?v={view_id}
```

⚠️ Save the ID to use it in development.

In your left sidebar, navigate to Settings & Members and then the Integrations tab.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w5uss7ce5764o9sfjdpn.png)

Click "Develop your own integrations".

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ohtk1249ypjf5zj7wkay.png)

Click the + New integration button.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w8qv2julfpya0yuvjcj9.png)

Setup settings of integration.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/harcz194fpbuf8ix8tux.png)

Copy the internal integration token.

⚠️ Save the token to use it in development.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jh0gj4abmrw22n0jxdc0.png)

Invite the integration which you created from the share menu.

### Settings of Google Sheets
Create a sheet to recieve messages from Slack and post them to Notion.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2vm3zm2r8j38ru9cgvlf.png)

| Question    |   Answer    |        URL |         Tags |
| ----------- | :---------: | ---------: | -----------: |
| sample text | sample text | https://dev.to/ | sample, tags |

Open Apps Script from within Google Sheets.

[📖 Lean more Extending Google Sheets](https://developers.google.com/apps-script/guides/sheets#get_started)

Get the script ID in Apps Script.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7sdy5q4bvzgji2tvv5nk.png)

⚠️ Save the ID to use it in development.

### Settings of Slack

We'll make an automation task with Workflow Builder in Slack.
[📖 Lean more Workflow Builder](https://slack.com/features/workflow-automation)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kth2vqet745gvetihhbw.png)

Create a new workflow.

### Workflow steps

Follow this order and set up these settings.

1. Emoji reaction
2. Send a form
3. Add a spreadsheet row
4. Send a message

#### 1. Emoji reaction

Choose "Emoji reaction" to start this workflow.
Feel free to select it.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ykwdhimqgwjrh6fcy459.png)

This workflow starts when someone adds the emoji reactions in the channel you've selected.

#### 2. Send a form

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/q6c2yn3aei8n87qkmvwz.png)

Select "Send a form" and add Questions like this below.

1. Question: Long answer
2. Answer: Long answer
3. URL: Short answer
4. Tags: Short answer

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ixqhc8tomhf58y6rbs6o.png)

Make Question and Answer to be required.

#### 3. Add a spreadsheet row

We can use Google Sheets for Workflow Builder to save and manage messages.

[📖 Lean more Google Sheets for Workflow Builder](https://slack.com/app-pages/google-sheets)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bpi6vv5b8a8eswzsi13u.png)

Choose "Add a spreadsheet row" from workflow options.

#### 4. Send a message
Create a message to respond to users.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/28utqi9cf4stlupuadnc.png)

Let's test the workflow in your slack channel.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mpylwnhzncbcdnt1wlva.png)

Of course, it's still not possible to post the message from Slack to Notion.

### Deploy Google Apps Script

We need to deploy Apps Script to post the message via Google Sheets from Slack to Notion.

I prepared a template for this project, so you don't have to spend extra time to develop.

https://github.com/Kazuki-tam/gas-slack2notion

#### 1. Clone template

Open the repository and click Use this template.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/11relt9q7lzw6zp0y8j7.png)

Clone the repository and install dependencies.

Install [Clasp](https://developers.google.com/apps-script/guides/clasp) at first if you haven't done it yet.

```bash
npm install -g @google/clasp
```

```bash
yarn install
```

[📖 Learn More Clasp](https://developers.google.com/apps-script/guides/clasp) 

#### 2. Login google account

Authorize management of your Google account's Apps Script projects.

```bash
npx clasp login
```

#### 3. Create files

Create a .clasp.json at the root, and then add these settings.
Open App script from your spreadsheet and check out a script Id at the setting page.

```json
{
  "scriptId": "<SCRIPT_ID>",
  "rootDir": "./dist"
}
```

Create a .env at the root, and then add your token and database id.

```
NOTION_TOKEN=<YOUR_NOTION_TOKEN>
DATABASE_ID=<YOUR_DATABASE_ID>
```

#### 4. Upload a script project

Upload your script project's files from your local with this command.

```bash
yarn deploy
```

To set up an installable trigger, click on the Trigger menu.
Click on it to add a trigger.

Set up these options like this.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7wx8dnxaput47lyks3lg.png)

### Test workflow

That's all you have to setup to create this project's workflow. Check if it works without problems.

## Conclusion

It's really important to share your knowledge and experience in your team and company. I hope this tutorial will help you to enhance your knowledge system.