HTTP Request node
Webhook node
+2

Line Message API : Push Message & Reply

Published 2 hours ago

Created by

darrelltw
darrell_tw

Template description

Workflow Description

This workflow demonstrates how to use the LINE Messaging API to handle two scenarios:

  1. Replying to a user's message using a reply token.
  2. Sending a push message to a specific LINE user using their user ID.

Key Features

  1. Webhook Integration: Receives and processes incoming messages from LINE using a webhook.
  2. Conditional Logic: Checks if the received event type is a message and handles it accordingly.
  3. Reply Message: Automatically responds to the user's message using the LINE reply token.
  4. Push Message: Sends a test message to a specific LINE user using their unique user ID.

Pre-Configuration

To simplify the setup process, create a Header Auth credential in n8n:

  • Name: Authorization
  • Value: Bearer {line token}
    This will authenticate all API requests to the LINE Messaging API.

Node Configurations

1.1. Webhook from LINE Message

  • Purpose: Captures incoming events from the LINE Messaging API.
  • Configuration:
    • HTTP Method: POST
    • Path: {n8n-webhook-page}

1.2. If Condition

  • Purpose: Checks if the received event type is message.
  • Configuration:
    • Condition:
      • {{ $json.body.events[0].type }} equals "message"

1.3. Line: Reply with Token

  • Purpose: Replies to the user's message using the LINE reply token.
  • Configuration:
    • Method: POST
    • URL: https://api.line.me/v2/bot/message/reply
    • JSON Body:
      {
        "replyToken": "{{ $('Webhook from Line Message').item.json.body.events[0].replyToken }}",
        "messages": [
          {
            "type": "text",
            "text": "收到您的訊息 : {{ $('Webhook from Line Message').item.json.body.events[0].message.text }}"
          }
        ]
      }
      

2.1. Manual Trigger: Test Workflow

  • Purpose: Triggers the workflow for testing the push message functionality.
  • Configuration: No additional setup required.

2.2. Edit Fields

  • Purpose: Prepares the unique LINE user ID for the push message.
  • Configuration:
    • Field:
      • line_uid: Uxxxxxxxxxxxx

2.3. Line: Push Message

  • Purpose: Sends a test message to a specific LINE user.
  • Configuration:
    • Method: POST
    • URL: https://api.line.me/v2/bot/message/push
    • JSON Body:
      {
        "to": "{{ $json.line_uid }}",
        "messages": [
          {
            "type": "text",
            "text": "推播測試"
          }
        ]
      }
      

工作流程描述

此工作流程展示如何使用 LINE Messaging API 處理兩種情境:

  1. 使用 reply token 回應使用者的訊息。
  2. 使用使用者的 user ID 發送 推播訊息

主要功能

  1. Webhook 整合:透過 Webhook 接收並處理來自 LINE 的訊息。
  2. 條件邏輯:檢查接收到的事件類型是否為訊息並進行處理。
  3. 回應訊息:使用 LINE 的 reply token 自動回覆使用者的訊息。
  4. 推播訊息:使用 LINE User ID 向指定用戶發送測試訊息。

預先設定

為簡化設定流程,請在 n8n 中建立 Header Auth 憑證:

  • 名稱Authorization
  • Bearer {line token}
    此設定將用於認證所有 LINE Messaging API 的請求。

節點設定

1.1. Webhook from LINE Message

  • 用途:接收來自 LINE Messaging API 的事件。
  • 設定
    • HTTP 方法POST
    • 路徑{n8n-webhook-page}

1.2. If 條件判斷

  • 用途:檢查接收到的事件類型是否為 message
  • 設定
    • 條件
      • {{ $json.body.events[0].type }} 等於 "message"

1.3. Line: Reply with Token

  • 用途:使用 LINE reply token 回應使用者訊息。
  • 設定
    • 方法POST
    • URLhttps://api.line.me/v2/bot/message/reply
    • JSON 主體
      {
        "replyToken": "{{ $('Webhook from Line Message').item.json.body.events[0].replyToken }}",
        "messages": [
          {
            "type": "text",
            "text": "收到您的訊息 : {{ $('Webhook from Line Message').item.json.body.events[0].message.text }}"
          }
        ]
      }
      

2.1. 手動觸發:測試工作流程

  • 用途:測試推播訊息功能。
  • 設定:無需額外設定。

2.2. Edit Fields

  • 用途:準備推播訊息所需的 LINE 使用者 ID。
  • 設定
    • 欄位
      • line_uidUxxxxxxxxxxxx

2.3. Line: 推播訊息

  • 用途:向特定 LINE 使用者發送測試訊息。
  • 設定
    • 方法POST
    • URLhttps://api.line.me/v2/bot/message/push
    • JSON 主體
      {
        "to": "{{ $json.line_uid }}",
        "messages": [
          {
            "type": "text",
            "text": "推播測試"
          }
        ]
      }
      

完成示意圖 (Storyboard Example):
Line_n8n_demo.png

Share Template

More Building Blocks workflow templates

Webhook node
Respond to Webhook node

Creating an API endpoint

Task: Create a simple API endpoint using the Webhook and Respond to Webhook nodes Why: You can prototype or replace a backend process with a single workflow Main use cases: Replace backend logic with a workflow
jon-n8n
Jonathan
Customer Datastore (n8n training) node

Very quick quickstart

Want to learn the basics of n8n? Our comprehensive quick quickstart tutorial is here to guide you through the basics of n8n, step by step. Designed with beginners in mind, this tutorial provides a hands-on approach to learning n8n's basic functionalities.
deborah
Deborah
HTTP Request node
Item Lists node

Pulling data from services that n8n doesn’t have a pre-built integration for

You still can use the app in a workflow even if we don’t have a node for that or the existing operation for that. With the HTTP Request node, it is possible to call any API point and use the incoming data in your workflow Main use cases: Connect with apps and services that n8n doesn’t have integration with Web scraping How it works This workflow can be divided into three branches, each serving a distinct purpose: 1.Splitting into Items (HTTP Request - Get Mock Albums): The workflow initiates with a manual trigger (On clicking 'execute'). It performs an HTTP request to retrieve mock albums data from "https://jsonplaceholder.typicode.com/albums." The obtained data is split into items using the Item Lists node, facilitating easier management. 2.Data Scraping (HTTP Request - Get Wikipedia Page and HTML Extract): Another branch of the workflow involves fetching a random Wikipedia page using an HTTP request to "https://en.wikipedia.org/wiki/Special:Random." The HTML Extract node extracts the article title from the fetched Wikipedia page. 3.Handling Pagination (The final branch deals with handling pagination for a GitHub API request): It sends an HTTP request to "https://api.github.com/users/that-one-tom/starred," with parameters like the page number and items per page dynamically set by the Set node. The workflow uses conditions (If - Are we finished?) to check if there are more pages to retrieve and increments the page number accordingly (Set - Increment Page). This process repeats until all pages are fetched, allowing for comprehensive data retrieval.
jon-n8n
Jonathan
Merge node

Joining different datasets

Task: Merge two datasets into one based on matching rules Why: A powerful capability of n8n is to easily branch out the workflow in order to process different datasets. Even more powerful is the ability to join them back together with SQL-like joining logic. Main use cases: Appending data sets Keep only new items Keep only existing items
jon-n8n
Jonathan
GitHub node
HTTP Request node
Merge node
+11

Back Up Your n8n Workflows To Github

This workflow will backup your workflows to Github. It uses the public api to export all of the workflow data using the n8n node. It then loops over the data checks in Github to see if a file exists that uses the workflow name. Once checked it will then update the file on Github if it exists, Create a new file if it doesn't exist and if it's the same it will ignore the file. Config Options repo_owner - Github owner repo_name - Github repository name repo_path - Path within the Github repository >This workflow has been updated to use the n8n node and the code node so requires at least version 0.198.0 of n8n
jon-n8n
Jonathan
HTTP Request node
WhatsApp Business Cloud node
+10

Building Your First WhatsApp Chatbot

This n8n template builds a simple WhatsApp chabot acting as a Sales Agent. The Agent is backed by a product catalog vector store to better answer user's questions. This template is intended to help introduce n8n users interested in building with WhatsApp. How it works This template is in 2 parts: creating the product catalog vector store and building the WhatsApp AI chatbot. A product brochure is imported via HTTP request node and its text contents extracted. The text contents are then uploaded to the in-memory vector store to build a knowledgebase for the chatbot. A WhatsApp trigger is used to capture messages from customers where non-text messages are filtered out. The customer's message is sent to the AI Agent which queries the product catalogue using the vector store tool. The Agent's response is sent back to the user via the WhatsApp node. How to use Once you've setup and configured your WhatsApp account and credentials First, populate the vector store by clicking the "Test Workflow" button. Next, activate the workflow to enable the WhatsApp chatbot. Message your designated WhatsApp number and you should receive a message from the AI sales agent. Tweak datasource and behaviour as required. Requirements WhatsApp Business Account OpenAI for LLM Customising this workflow Upgrade the vector store to Qdrant for persistance and production use-cases. Handle different WhatsApp message types for a more rich and engaging experience for customers.
jimleuk
Jimleuk

Implement complex processes faster with n8n

red icon yellow icon red icon yellow icon