Complete Guide to Integrating Dify AI with LINE Chatbot

Use Dify AI’s powerful features to quickly create and integrate a LINE chatbot, making automated conversations easier. This tutorial will guide you step-by-step through the integration process using dmflow.chat, complete with examples and important tips.

What is Dify?

Dify is an open-source large language model (LLM) application platform designed to simplify the development and deployment of generative AI applications. It integrates core technologies, combining Backend as a Service (BaaS) with LLMOps, allowing developers (even non-technical users) to quickly build and manage production-grade AI applications.

Introduction

Dify AI offers a graphical design interface and API integration capabilities, enabling you to streamline complex workflows into a LINE chatbot for various use cases.

Complete Guide to Integrating Dify AI with LINE Chatbot

For this example, we will use the default template: SaaS Startup Mentor.

SaaS Startup Mentor

Resource Node Settings

The template includes a variable called founder_profile, but it is optional and not used in this example.

Variables used:

  • user_id: for user
  • conversation_id: for conversation_id
  • query: for the user’s query
  • output: for the answer

Request Example:

curl -X POST 'https://api.dify.ai/v1/chat-messages' \
--header 'Authorization: Bearer {api_key}' \
--header 'Content-Type: application/json' \
--data-raw '{
    "inputs": {},
    "query": "What are the specs of the iPhone 13 Pro Max?",
    "response_mode": "streaming",
    "conversation_id": "",
    "user": "abc-123",
    "files": [
      {
        "type": "image",
        "transfer_method": "remote_url",
        "url": "https://cloud.dify.ai/logo/logo-site.png"
      }
    ]
}'

Response Example:

{
    "event": "message",
    "message_id": "9da23599-e713-473b-982c-4328d4f5c78a",
    "conversation_id": "45701982-8118-4bc5-8e9b-64562b4555f2",
    "mode": "chat",
    "answer": "iPhone 13 Pro Max specs are listed here:...",
    "metadata": {
        "usage": {
            "prompt_tokens": 1033,
            "prompt_unit_price": "0.001",
            "prompt_price_unit": "0.001",
            "prompt_price": "0.0010330",
            "completion_tokens": 128,
            "completion_unit_price": "0.002",
            "completion_price_unit": "0.001",
            "completion_price": "0.0002560",
            "total_tokens": 1161,
            "total_price": "0.0012890",
            "currency": "USD",
            "latency": 0.7682376249867957
        },
        "retriever_resources": [
            {
                "position": 1,
                "dataset_id": "101b4c97-fc2e-463c-90b1-5261a4cdcafb",
                "dataset_name": "iPhone",
                "document_id": "8dd1ad74-0b5f-4175-b735-7d98bbbb4e00",
                "document_name": "iPhone List",
                "segment_id": "ed599c7f-2766-4294-9d1d-e5235a61270a",
                "score": 0.98457545,
                "content": "\"Model\",\"Release Date\",\"Display Size\",\"Resolution\",\"Processor\",\"RAM\",\"Storage\",\"Camera\",\"Battery\",\"Operating System\"\n\"iPhone 13 Pro Max\",\"September 24, 2021\",\"6.7 inch\",\"1284 x 2778\",\"Hexa-core (2x3.23 GHz Avalanche + 4x1.82 GHz Blizzard)\",\"6 GB\",\"128, 256, 512 GB, 1TB\",\"12 MP\",\"4352 mAh\",\"iOS 15\""
            }
        ]
    },
    "created_at": 1705407629
}

We use two resources:

  1. Call this resource when conversation_id is empty.
  2. Call another resource when conversation_id exists.

Additionally, save the temporary conversation_id in the session by adding it to the memory template.

Resource Node Settings

Conversation Flow Design

  1. Start Node: No text input required.
  2. Resource Node: Called if conversation_id exists.
  3. Resource Node: Called if conversation_id does not exist.
  4. Reply Node: Disable the wait for response option.
  5. Variable Node: Assign the retrieved conversation_id to session.conversationId.
  6. Branch Node: Check if session.conversationId exists.

Conversation Flow Design

Final Output

After integration, the LINE chatbot will respond in real time with processed results.
Click to view the detailed tutorial: Channel Integration Tutorial

Final Output

By following these steps, you have successfully integrated Dify with the LINE chatbot! Start creating efficient automated conversations now to improve service quality.

Reference: How to Use Dify AI

Share on:
Previous: What is Coze?
Next: Building Efficient Workflows with Dify AI to Save Time and Costs