DEV Community

loading...

Integrating LINE Message and Zapier

basman profile image Adam.S ・4 min read

The most common text messaging service used in Japan is by far LINE. I have been using LINE for some time now with Zapier to get notifications directly on my phone without needing to install other services.

This will be a brief guide aimed at those that are already familiar with Zapier and LINE and would like to bring the two together.

For those that are less familiar. I would direct your attention to this link where I have some additional details.

Prerequisites:

  • Gmail
  • Zapier Account
  • LINE Messenger

Gmail:

First setup a filter in Gmail which adds a label to any message that you would like to have trigger a LINE message using Zapier.
There are several good guides on doing this.
Google provides a guide here

For the purposes of this guide I will assume you are using 'ZapierLine' as the label.

Next we will setup LINE

Step 1:

Log into the site here. This supports English, Japanese and a few other languages. Note: You will need to have setup your email address and password in advance using the mobile app.

Step 2:

Click on the 'My page'

Alt Text

Step 3:
Click on 'Generate token'

Alt Text

Step 4:
Provide a name for token. In this case I have provided 'ZapierDemo'. This will appear on your phone as the sender of the notification.

Alt Text

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.

Here I have chosen '1-on-1'

Alt Text

Step 6:
Copy the generated token and set save it in a safe place as you will see this once.

Alt Text

Zapier:

From here we will create a Zap which will be triggered when an email arrives in your account and has been labeled 'ZapierLine' by the filter you previously created.

Step 1:
Log in to Zapier and click 'MAKE A ZAP' or 'Create Zap'

Alt Text

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'

Alt Text

Step 3:
Choose your 'Trigger Event'
You should choose 'New Thread'

Alt Text
Alt Text

Step 4:
Click 'Continue'

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

Alt Text
Click 'Continue'

Step 6:
Select the correct Gmail Label. In this case we are using 'ZapierLine'

Alt Text
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'

Alt Text
If you are happy with the result. Click 'Continue'

Step 8:
Enter 'Code by Zapier' and click on 'Code by Zapier'

Alt Text
Step 9:
For 'Choose Action Event' select 'Run Python'

Alt Text

Click 'Continue'

Step 10:

At this point we will start selecting what information we want to extract from the email.
This is of course is 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 manually.

I will then select from the drop down the actual items I am looking for.

Alt Text

Alt Text

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

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

Sample 1

   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}
Enter fullscreen mode Exit fullscreen mode

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

  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}
Enter fullscreen mode Exit fullscreen mode

Alt Text

Alt Text

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
Alt Text
Alt Text

known Issues:
*Zapier now only runs every 15 minutes for new free accounts.
*There is a 1 second runtime limit. You may get a warning if your code takes longer to execute.

These limits can be removed by upgrading your service.

Discussion (3)

Collapse
robert1112 profile image
Robert C

Hi Adam,

It is a nice post. Do you think it is possible to get user‘s name or content from LINE@ and pass it to Zapier for processing? Thank you.

Collapse
basman profile image
Adam.S Author

Hi Robert,

I actually don't know. I believe it's a different though related service.
I think LINE@ has been replaced/renamed.

Sorry.

Collapse
robert1112 profile image
Robert C

Hi Adam

You are right. Line@ is renamed LINE official. Thank you for your sharing. It really saves my life (and days).

Forem Open with the Forem app