Skip to content
This repository has been archived by the owner on Aug 11, 2022. It is now read-only.

kemsakurai/gas-Gmail2Slack

Repository files navigation

gas-gmail2slack

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.


Copy and use spreadsheet

Here's how to copy and use the spreadsheet.

  • Source spreadsheet
    gas-Gmail2Slack
    The Initial Settings has been completed.

  • Permissions you need to grant The following permissions are required to execute the script.
    Image from Gyazo

  • Slack notification image
    After setting, the message of the following image is notified.
    Image from Gyazo

Usage

Describes how to use it.

Enable Incoming Webhooks, get and set URL

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, select gas-Gmail2Slack, then click Initial Settings, Webhook URL Settings.
    Image from Gyazo
    A dialog will be displayed, so set the URL of the issued webhook.
    Image from Gyazo

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
  • Channel
    Enter the Slack channel name of the notification destination. # is the beginning.

    • Example
      #gsc
  • SendTo
    It will be the Slack account name of the recipient.

    • Example
      @monotalk_xyz
  • Message body length
    Enter the length of the email body. If you want to display only the title, enter 0 to display only the title.

    • Example
      1000
  • Query
    Set up a Gmail search query. Chat messages sent by Slack on Google Apps Script side are marked as read, so if you add is: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

Schedule execution settings

From the menu, select gas-Gmail2Slack and click Initial Settings, Schedule Run.
Image from Gyazo
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.
Image from Gyazo


Clone Github repository and build

Install clasp

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    

Clone the Git repository, create a new spreadsheet, build Google Apps Script and push.

  • 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, run npm 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.

Copy and use pre-built resources

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.


LICENCE

MIT