How to Connect Two LINE Chatbots - Seamless Switching with Sub-scenarios

Description

This article explains how to connect two LINE chatbots using the sub-scenario feature. With this approach, you can make your business processes more flexible and complete. We will cover implementation methods, setup steps, and key considerations.

Why Connect Two LINE Chatbots?

Connecting two LINE chatbots offers several benefits:

  1. Modular Functions: Each bot can handle specific business logic, making the system easier to maintain.
  2. Flexible Expansion: Easily integrate new chatbot functionalities as needed.
  3. Resource Optimization: Utilize different bots for different scenarios to improve resource efficiency.

Implementation Method

Preparation

The sub-scenario feature temporarily pauses the current scenario and calls other HTTP methods. This method is similar to the integration of native LINE customer service previously discussed.

Step 1: Generate Encryption Key

  1. Go to the text template testing section.
  2. Enter your LINE secret in {{Utils.encrypt('xxx')}} to generate the encryption key and copy it.

Generate Key in Text Template

If you’re unsure how to find your LINE secret, refer to the guide: Setting Up LINE Webhook.

Step 2: Configure Resource Node

In the resource node, configure the following:

  1. Fill in the third-party webhook URL.
  2. Generate the x-line-signature value using this format:
    {{Utils.generateSignature('{"events":['+data.conversation._message.raw_event+']}',Utils.decrypt('Your Encrypted Bot Key'),'HMACSHA256')}}
    
  3. Set the event request path to events[0] in Body Params.
  4. Use {"events":[{}]} as the Payload.

Resource Node Configuration

Step 3: Define the Process Flow

You need to set up two main processes:

  1. Transfer Process:
    Transfer Process

  2. Current Process:
    Current Process

Step 4: Configure Sub-scenario

In the sub-scenario configuration:

  1. Use a listening node for the transfer_webhook scenario node.
  2. Name the sub-scenario node as sub_transfer (customizable).
  3. Set trigger conditions for the listening node, such as ending the node when the inquiry equals [wake_up].

Sub-scenario Configuration

Real-world Demonstration

The following image shows the user interface before and after switching between bots. Users can click the “Back” button to return to the first chatbot:

Switching Demonstration

Key Considerations

  1. Consistent Channel ID: Both chatbots must use the same channel ID.
  2. Feature Limitations:
    • Only text and attachments are supported for transfer.
    • Events like follow and unfollow are not forwarded.
  3. Use Case: This method is primarily for extending existing systems to call other bots, rather than being a feature specifically designed for connecting multiple chatbots.

Conclusion

Connecting two LINE chatbots significantly enhances process flexibility and creates a more comprehensive service. Using sub-scenarios, you can easily implement seamless transitions between chatbots, improving the user experience. Be mindful of the limitations and configuration requirements to ensure proper system operation during implementation.

Share on:
Previous: Building Efficient Workflows with Dify AI to Save Time and Costs
Next: AI Forward Weekly Report 2024-11-23: Breakthroughs and Challenges