Welcome to GMAIL + Zapier + LINE’s Notifications documentation!

This is a guide to get LINE notifcations sent when you receive certain emails in your Gmail account. It appears that LINE in the past had a service with Zapier which has since been discontinued.

Line + Zapier in the past.

It appears that LINE used to provide a service with Zapier, but his ended some time in the past.

Previous guides I have found are here and here for Japanese guide.

Setting up Gmail.

Setup a filter and label.

Create a filter using the required search conditions and apply a label that you can use with Zapier. This has been documented in many places, so I will not go into details.

For this tutorial I will assume you have a filter that adds the label: ZapierLine

Setting up LINE.

Outline.

Will will be doing the following steps:

  1. Log into LINE Notify Bot
  2. Create a group or user Token (Ensure that you copy this as you will see it only once)

The Steps:

Step 1:

Log into the site here. This supports English, Japanese and a few other languages.

Step 2:

Click on the ‘My page’

My Page link

Step 3:

Click on ‘Generate token’

Generate Token

Step 4:

Provide a name for the token. In this case I have provided ‘ZapierDemo’

Provide Token name

Step 5: Choose if you want to send notifications only to yourself using ‘1-on-1 chat with LINE Notify’ or choose an existing chat group you have created within the LINE App on your device. In this case I have chosen ‘1-on-1’

Choose your chat group or one on one.

Click on ‘Generate token’

Step 6:

Copy the generated token as you will only see this once.

Generate Token Example

Setting Up Zapier.

Outline

This will take you through creating a Zap for sending notifications to your selected chat user or group. I will not provide instructions on creating a Zapier account. I believe this is fairly simple and straight forward. Linking your google account to Zapier.

The Steps:

Step 1:

Either Click ‘MAKE A ZAP’ or ‘Create Zap’

_images/1-Zapier-CreateZap.png

Step 2:

Give your Zap a name. I have used ‘ZapierDemo’ If you don’t see Gmail in the app list, enter it in the search as I have done. Click on ‘Gmail’

_images/2-Zapier-Gmail.png

Step 3:

Choose your ‘Trigger Event’ You should choose ‘New Thread’

_images/3-Zapier-Gmail-Thread-Select.png _images/4-Zapier-Gmail-Thread.png

Step 4:

Click ‘Continue’

Step 5:

Select your connected Gmail account. This will tell Zapier which gmail account to monitor.

_images/5-Zapier-Choose-Account.png

Click ‘Continue’

step 6:

Select the correct Gmail Label. In this case we are using ‘ZapierLine’

_images/6-Zapier-Choose-Label.png

Click ‘Continue’

Step 7:

Next we need to ‘Test your Trigger’. So click this button.

This will now look for any messages that contain the label we have provided. ‘ZapierLine’

_images/8-Zapier-Thread-Sample.png

If you are happy with the result. Click ‘Continue’

Step 8:

Enter ‘Code by Zapier’ and click on ‘Code by Zapier’

_images/9-Zapier-Code-By-Zapier.png

Step 9:

For ‘Choose Action Event’ select ‘Run Python’

_images/10-Zapier-Run-Python.png

Click ‘Continue’

Step 10:

At this point we will start selecting what information we want to extract from the email. This is of course optional. If you wish you could simply have a notification sent to your line account letting you know to check your email. However in this case we will collect some data to add to the notification.

I will extract the following details. from, subject and body. These names are provided by me. I will then select from the drop down the actual items I am looking for.

_images/11-Zapier-Extraction.png _images/12-Zapier-Extraction-Complete.png

Next we need to enter our code in the code window.

Sample 1: This code simply takes the plain text body of the email and sends it in the notification.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
import requests
API_URI = "https://notify-api.line.me/api/notify"

text_message = input.get('body')
TOKEN = "YOUR_GENERATED_TOKEN_GOES_HERE"
HEADER = {"Authorization": "Bearer " + TOKEN}
PARAMS = {"message": text_message}

response = requests.post(API_URI, headers=HEADER, params=PARAMS)
response.raise_for_status()
return {'rawHtml': response.text}

Sample 2: This code sends a different text message depending on the from address of the sender.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
import requests
API_URI = "https://notify-api.line.me/api/notify"

if input.get('from') == 'AddressA':
   text_message = "This is the message from sender A"
if input.get('from') == 'AddressB':
   text_message = "This is the message from sender B with email body included:\n\n{}".format(input.get('body'))

TOKEN = "YOUR_TOKEN_GOES_HERE"
HEADER = {"Authorization": "Bearer " + TOKEN}
PARAMS = {"message": text_message}

response = requests.post(API_URI, headers=HEADER, params=PARAMS)
response.raise_for_status()
return {'rawHtml': response.text}
_images/13-Zapier-Test.png _images/14-Zapier-Result.png

NOTE: If you get an error message that execution took more than 1 second. This can be ignored. Simply Click the ‘Skip Test’ in the upper right corner.

Step 11:

Activate your ZAP

_images/15-Zapier.png _images/16-Zapier.png

Known Issues

Zapier Basic

If you are using the free basic version of Zapier. There is a one second run-time limit. If the code exceeds this limit you will receive a warning notice. In my experience this has not caused any issues with the actual execution of the code.

It appears that Zapier has also extended the time between runs. It used to be 5 minutes. It is now 15 minutes for the free account.