A Google Apps Script that notifies Slack of emails that match a Gmail search query and marks the emails as read. The search query, the room information to notify, and the sender's account are read from the spreadsheet.
Here's how to copy and use the spreadsheet.
-
Source spreadsheet
gas-Gmail2Slack
TheInitial Settings
has been completed. -
Permissions you need to grant The following permissions are required to execute the script.
-
Slack notification image
After setting, the message of the following image is notified.
Describes how to use it.
Enable Incoming Webhooks and get the URL to populate the spreadsheet.
-
Enable Incoming Webhooks
Use Incoming Webhooks to notify Slack channels. Currently, there are old-style Incoming Webhooks and new-style Imcoming Webhooks, and this spreadsheet works with the old-style. The following article was easy to understand about the setting procedure of the old method.
SlackのIncoming Webhooksを使い倒す - Qiita -
Set URL to spreadsheet
From the menu, selectgas-Gmail2Slack
, then clickInitial Settings
,Webhook URL Settings
.
A dialog will be displayed, so set the URL of the issued webhook.
In the Config sheet, enter the Gmail information to be notified and the Slack channel to be notified.
The column contents of the Config sheet are explained.
-
Tag Enter a one-line comment. Slack will be notified as a
tag
.- Example
Google Search Console
- Example
-
Channel
Enter the Slack channel name of the notification destination.#
is the beginning.- Example
#gsc
- Example
-
SendTo
It will be the Slack account name of the recipient.- Example
@monotalk_xyz
- Example
-
Message body length
Enter the length of the email body. If you want to display only the title, enter0
to display only the title.- Example
1000
- Example
-
Query
Set up a Gmail search query. Chat messages sent by Slack on Google Apps Script side are marked as read, so if you addis:unread
, only unread messages will be notified.
Search operators you can use with Gmail - Gmail Help describes what search operators are available.- Example
is:unread label:google-search-console
- Example
From the menu, select gas-Gmail2Slack
and click Initial Settings
, Schedule Run
.
In the dialog, set the execution schedule. If you choose every hour
, the script will be run every hour and Slack will be notified by email.
You will need to install clasp to deploy the container binding script.
For the installation of clasp, you may find the following articles helpful.
google/clasp: 🔗 Command Line Apps Script Projects
- Install clasp
npm i @google/clasp -g
- clasp login
clasp login
- Git clone
git clone https://github.com/kemsakurai/gas-Gmail2Slack.git <project_name>
- nom install
cd <project_name>
npm install
- Create a new spreadsheet
To create a new spreadsheet, runnpm run setup
. Execute command to initialize .clasp.json and create a spreadsheet.
npm run setup
- Deploy container bind script
npm run deploy
This will create a spreadsheet called gas-Gmail2Slack
in G Suite.
If the public spreadsheet cannot be copied with the G Suite security settings and you have trouble building and deploying it, gas-Gmail2Slack/dist at master · kemsakurai/gas-Gmail2Slack as a container binding script.
MIT