Back to HomeDialogflow

Dialogflow LINE Bot Integration Tutorial: Building AI Customer Service

12 min min read
#Dialogflow#LINE Bot#Messaging API#Chatbot#AI Customer Service

Dialogflow LINE Bot Integration Tutorial: Building AI Customer Service

Dialogflow LINE Bot Integration Tutorial: Building AI Customer Service

LINE is the most commonly used messaging app in Taiwan, with over 21 million monthly active users. If your customers are on LINE, then putting AI customer service in LINE is the most direct approach.

This article teaches you step-by-step how to integrate Dialogflow with LINE to build 24/7 AI customer service bots with automatic responses. No complex programming skills needed—follow the steps and you can complete basic integration in 30 minutes.

If you're not yet familiar with Dialogflow, we recommend first reading the Dialogflow Complete Guide.


Prerequisites

Before starting integration, you need to prepare the following accounts and environments.

LINE Developers Account Registration

  1. Go to LINE Developers
  2. Log in with your LINE account
  3. Agree to developer terms
  4. Create a Provider (can use company name or project name)

Dialogflow Agent Setup

Ensure you already have a Dialogflow Agent:

  1. Go to Dialogflow Console
  2. Create new Agent or use existing Agent
  3. Confirm language settings include your target language

Google Cloud Project Setup

Dialogflow Agent automatically associates with a Google Cloud project. Confirm these settings:

  1. Go to Google Cloud Console
  2. Select the project corresponding to your Dialogflow Agent
  3. Confirm Dialogflow API is enabled

Required permissions:

  • Dialogflow API Admin
  • Service Account User (if using service accounts)

Illustration: Prerequisites Checklist Diagram

Scene Description: A checklist-style diagram, left side shows three preparation items: LINE Developers account (LINE icon), Dialogflow Agent (Dialogflow icon), Google Cloud project (GCP icon). Each item has a checkbox next to it indicating completion status.

Visual Focus:

  • Main content clearly presented

Required Elements:

  • Based on key elements in description

Chinese Text to Display: None

Color Tone: Professional, clear

Elements to Avoid: Abstract graphics, gears, glowing effects

Slug: dialogflow-line-prerequisites-checklist


Step 1: Create LINE Channel

LINE Bot needs a "Messaging API Channel" to send and receive messages.

Create Messaging API Channel

  1. Log in to LINE Developers Console
  2. Select your Provider
  3. Click "Create a new channel"
  4. Select "Messaging API"

Fill in Channel information:

FieldDescriptionExample
Channel nameBot display name"XX Company Service"
Channel descriptionBot description"24/7 Smart Customer Service"
CategoryBusiness categorySelect closest category
SubcategorySubcategorySelect closest category
EmailContact emailYour Email
  1. Agree to LINE Terms of Service
  2. Click "Create"

Get Channel Access Token

Channel Access Token is the key for external programs to operate LINE Bot.

  1. Enter the newly created Channel
  2. Switch to "Messaging API" tab
  3. Scroll to "Channel access token" section
  4. Click "Issue" to generate Token
  5. Copy and safely store this Token

Configure Webhook URL

Webhook URL tells LINE where to forward messages.

If using Dialogflow ES:

  1. Return to Dialogflow Console
  2. Click the gear icon (Settings) in left menu
  3. Switch to "Integrations" tab
  4. Find "LINE" and click
  5. Enter the Channel Access Token just obtained
  6. Copy the Webhook URL provided by Dialogflow

Return to LINE Developers Console:

  1. In "Messaging API" tab
  2. Find "Webhook settings" section
  3. Paste the Webhook URL
  4. Turn on "Use webhook" switch

Illustration: LINE Channel Settings Screenshot

Scene Description: A screenshot of LINE Developers Console showing Messaging API settings page. The screen highlights Channel Access Token and Webhook URL locations, with red boxes marking key configuration items.

Visual Focus:

  • Main content clearly presented

Required Elements:

  • Based on key elements in description

Chinese Text to Display: None

Color Tone: Professional, clear

Elements to Avoid: Abstract graphics, gears, glowing effects

Slug: line-developers-channel-settings


Step 2: Configure Dialogflow Integration

ES and CX have different LINE integration methods.

Enable LINE Integration (ES Version)

Dialogflow ES has built-in LINE integration, setup is simple:

  1. In Dialogflow Console, enter your Agent
  2. Click "Integrations" on the left
  3. Find LINE and click
  4. Enter the following information:
FieldSource
Channel IDLINE Developers > Basic settings
Channel SecretLINE Developers > Basic settings
Channel Access TokenToken just generated
  1. Click "Start" to enable integration
  2. Copy the displayed Webhook URL
  3. Return to LINE Developers and paste Webhook URL

Using Cloud Functions Middleware (CX Version)

Dialogflow CX doesn't have built-in LINE integration, you need to build your own middleware service.

Architecture explanation:

LINE → Cloud Functions → Dialogflow CX → Cloud Functions → LINE

Create Cloud Function:

  1. Go to Google Cloud Console
  2. Select Cloud Functions
  3. Click "Create Function"

Basic settings:

  • Function name: dialogflow-line-webhook
  • Region: asia-east1 (Taiwan)
  • Trigger type: HTTP
  • Authentication: Allow unauthenticated invocations

Code (Node.js):

const line = require('@line/bot-sdk');
const {SessionsClient} = require('@google-cloud/dialogflow-cx');

const lineConfig = {
  channelAccessToken: process.env.LINE_CHANNEL_ACCESS_TOKEN,
  channelSecret: process.env.LINE_CHANNEL_SECRET,
};

const lineClient = new line.Client(lineConfig);

const projectId = process.env.GCP_PROJECT_ID;
const location = 'asia-northeast1';
const agentId = process.env.DIALOGFLOW_AGENT_ID;

exports.webhook = async (req, res) => {
  const events = req.body.events;

  for (const event of events) {
    if (event.type === 'message' && event.message.type === 'text') {
      const userId = event.source.userId;
      const userMessage = event.message.text;

      // Call Dialogflow CX
      const response = await detectIntent(userId, userMessage);

      // Reply to LINE
      await lineClient.replyMessage(event.replyToken, {
        type: 'text',
        text: response,
      });
    }
  }

  res.status(200).send('OK');
};

async function detectIntent(sessionId, text) {
  const client = new SessionsClient();

  const sessionPath = client.projectLocationAgentSessionPath(
    projectId,
    location,
    agentId,
    sessionId
  );

  const request = {
    session: sessionPath,
    queryInput: {
      text: {
        text: text,
      },
      languageCode: 'en-US',
    },
  };

  const [response] = await client.detectIntent(request);

  // Get reply text
  const messages = response.queryResult.responseMessages;
  let replyText = '';

  for (const message of messages) {
    if (message.text) {
      replyText += message.text.text.join('\n');
    }
  }

  return replyText || 'Sorry, I don\'t quite understand what you mean.';
}

Environment variable setup:

  • LINE_CHANNEL_ACCESS_TOKEN: LINE Channel Token
  • LINE_CHANNEL_SECRET: LINE Channel Secret
  • GCP_PROJECT_ID: Google Cloud Project ID
  • DIALOGFLOW_AGENT_ID: Dialogflow CX Agent ID

Deployment:

  1. Deploy Cloud Function
  2. Copy trigger URL
  3. Return to LINE Developers to set Webhook URL

For more Webhook development details, refer to Dialogflow Fulfillment and API Integration Tutorial.


Having trouble with integration? LINE and Dialogflow integration has many details—figuring it out yourself could take a long time. Book technical consultation to have experienced people help you quickly solve issues.


Step 3: Integration Testing

After setup is complete, let's test whether integration is successful.

Basic Testing

  1. Open LINE on your phone
  2. Add the newly created LINE Bot as friend (QR Code can be found in LINE Developers > Messaging API)
  3. Send message "Hello"
  4. Confirm Bot replies

Expected result: Bot should reply with Default Welcome Intent content.

Debugging Methods

If Bot doesn't reply:

  1. Check Webhook settings

    • Is LINE Developers > Webhook URL correct
    • Is "Use webhook" turned on
  2. Check Dialogflow integration status

    • Does Dialogflow > Integrations > LINE show "Running"
  3. View LINE error messages

    • LINE Developers > Messaging API > "Verify" button
    • Click to test Webhook connection
  4. View Cloud Functions logs (CX version)

    • Google Cloud Console > Cloud Functions > Select Function > Logs

Common errors:

ErrorCauseSolution
400 Bad RequestWebhook URL format errorConfirm URL is HTTPS
401 UnauthorizedChannel Token errorRegenerate Token
500 Internal ErrorDialogflow configuration issueCheck Agent language settings
TimeoutWebhook response too slowOptimize Fulfillment or increase Timeout

Illustration: LINE Bot Test Conversation Screenshot

Scene Description: A phone screen screenshot showing LINE conversation interface. User sends "Hello," Bot replies with welcome message. Then user asks "Business hours," Bot replies with business hours information. Conversation bubbles clearly show back-and-forth interaction.

Visual Focus:

  • Main content clearly presented

Required Elements:

  • Based on key elements in description

Chinese Text to Display: None

Color Tone: Professional, clear

Elements to Avoid: Abstract graphics, gears, glowing effects

Slug: line-bot-dialogflow-test-conversation


Advanced Features

After basic integration is complete, you can add richer interactive features.

Quick Reply Buttons

Quick Reply lets users click buttons to reply without typing.

ES version configuration:

Use LINE-specific format in Intent Response:

{
  "line": {
    "type": "text",
    "text": "Please select service type:",
    "quickReply": {
      "items": [
        {
          "type": "action",
          "action": {
            "type": "message",
            "label": "Reservation",
            "text": "I want to make a reservation"
          }
        },
        {
          "type": "action",
          "action": {
            "type": "message",
            "label": "Check Order",
            "text": "Check order"
          }
        }
      ]
    }
  }
}

CX version: Compose LINE format in Fulfillment and return.

Flex Message Integration

Flex Message can create card-style rich content, suitable for displaying products, order information, etc.

Example: Product Card

{
  "type": "flex",
  "altText": "Product Information",
  "contents": {
    "type": "bubble",
    "hero": {
      "type": "image",
      "url": "https://example.com/product.jpg",
      "size": "full",
      "aspectRatio": "20:13"
    },
    "body": {
      "type": "box",
      "layout": "vertical",
      "contents": [
        {
          "type": "text",
          "text": "Product Name",
          "weight": "bold",
          "size": "xl"
        },
        {
          "type": "text",
          "text": "$120.00",
          "size": "lg",
          "color": "#ff0000"
        }
      ]
    },
    "footer": {
      "type": "box",
      "layout": "vertical",
      "contents": [
        {
          "type": "button",
          "action": {
            "type": "message",
            "label": "Add to Cart",
            "text": "Purchase Product A"
          }
        }
      ]
    }
  }
}

Rich Menu Configuration

Rich Menu is the fixed menu at the bottom of LINE chat room, providing common feature entry points.

Configuration method:

  1. Go to LINE Official Account Manager
  2. Select your Official Account
  3. Click "Rich Menu"
  4. Design menu image and button areas
  5. Set text to send for each area click

Design suggestions:

  • Include 3-6 common features
  • Button text should be concise
  • Icons should be clear and easy to understand

Illustration: LINE Rich Menu Design Example

Scene Description: A LINE chat interface screenshot, bottom showing Rich Menu. Menu has 6 buttons: "Book," "Menu," "Hours," "Location," "Contact Us," "Promotions"—each button has a corresponding icon. Overall design is clean and professional.

Visual Focus:

  • Main content clearly presented

Required Elements:

  • Based on key elements in description

Chinese Text to Display: None

Color Tone: Professional, clear

Elements to Avoid: Abstract graphics, gears, glowing effects

Slug: line-rich-menu-design-example


Practical Example: Restaurant Reservation Bot

Let's look at a complete practical example: a restaurant reservation bot.

Conversation Flow Design

User: I want to make a reservation
Bot: OK, what date would you like to dine?
User: Tomorrow
Bot: What time would you like to dine?
User: 7 PM
Bot: How many guests?
User: 4
Bot: What name for the reservation?
User: John Smith
Bot: Confirming reservation:
    Date: Tomorrow
    Time: 7:00 PM
    Party: 4
    Name: John Smith
    Is this correct?
User: Yes
Bot: Reservation complete! We'll send a confirmation text to your phone.

Intent Design

IntentTraining PhrasesParameters
start_bookingI want to book, make reservation-
provide_datetomorrow, 12/25, next Saturday@sys.date
provide_time7 PM, 19:00@sys.time
provide_party_size4 guests, four people@sys.number
provide_namemy name is John, John Smith@sys.person
confirm_bookingyes, correct, confirm-
cancel_bookingno, wrong, start over-

Context Chaining

Use Context to remember conversation state:

  1. "start_booking" sets Output Context: booking
  2. "provide_date" requires Input Context: booking, sets Output Context: booking-date
  3. And so on, ensuring Context correctly passes at each step

For detailed Intent and Context design, refer to Dialogflow Intent and Context Complete Tutorial.


FAQ and Debugging

What If Bot Responds Slowly?

Possible causes:

  1. Fulfillment calling external API too slowly
  2. Cold Start (Cloud Functions cold start)
  3. Network latency

Solutions:

  • Optimize API calls, add caching
  • Use Cloud Functions minimum instances setting
  • Choose Region close to users

What If Language Understanding Is Inaccurate?

Solutions:

  1. Add Training Phrases covering different phrasings
  2. Use local terminology and colloquialisms
  3. Use Entities to extract key information
  4. Regularly review conversation records, find failed recognition cases

Does LINE Have Message Limits?

Free plan limits:

  • 500 free broadcast messages per month
  • Unlimited reply messages

Note: Dialogflow replies are "reply messages" and don't count against broadcast quota. But proactive notifications (like order updates) count against broadcast quota.

How to Handle Image and File Messages?

Default Dialogflow integration only handles text messages. If you need to handle images:

  1. Use CX + Cloud Functions custom integration
  2. Determine message type in Cloud Functions
  3. Images can be analyzed with Vision API before sending to Dialogflow

For integration with other platforms, refer to Dialogflow Messenger and WhatsApp Integration Guide.


Next Steps

After LINE Bot integration is complete, you can:

  1. Optimize Conversation Design: Dialogflow Intent and Context Complete Tutorial
  2. Add Backend Logic: Dialogflow Fulfillment and API Integration Tutorial
  3. Integrate More Platforms: Dialogflow Messenger and WhatsApp Integration Guide
  4. Control Costs: Dialogflow Pricing Complete Analysis

Illustration: LINE Bot Feature Expansion Roadmap

Scene Description: A roadmap starting from "Basic Integration," branching into four directions: "Conversation Design Optimization," "Backend System Integration," "Multi-Platform Expansion," "Data Analytics." Under each direction lists specific feature items.

Visual Focus:

  • Main content clearly presented

Required Elements:

  • Based on key elements in description

Chinese Text to Display: None

Color Tone: Professional, clear

Elements to Avoid: Abstract graphics, gears, glowing effects

Slug: line-bot-feature-expansion-roadmap


Want to Build Enterprise-Grade LINE AI Customer Service?

If you want:

  • 24/7 automatic customer question responses
  • Integration with order systems, member systems
  • Support for complex multi-turn conversations
  • Professional assistance with development and maintenance

Book AI implementation consultation to have experienced people help plan a complete solution.

We've helped multiple enterprises build LINE AI customer service, consultation is completely free.


Need Professional Cloud Advice?

Whether you're evaluating cloud platforms, optimizing existing architecture, or looking for cost-saving solutions, we can help

Book Free Consultation

Related Articles