Here is the full English translation of your document titled “AI Bot Development: Integration of RongCloud IM with Dify – A Practical Guide”:


AI Bot Development: RongCloud IM and Dify Integration Guide

Author: wangqijia|RongCloud Developer Team Date: June 2025


1. Overview

RongCloud IM PaaS provides comprehensive AI bot management capabilities, supporting rich event callbacks triggered by specific bots. This enables developers to flexibly handle various business scenarios, such as:

  • Initiating one-on-one conversations with bots
  • Using @mention to trigger contextual responses

In addition, the platform comes with built-in integration capabilities for AI platforms, allowing bot messages to be automatically forwarded to connected LLM platforms (e.g., Dify). This eliminates the need for an intermediate service layer, greatly improving the stability of message flow, reducing integration costs, and accelerating development delivery.

This guide will walk you through integrating AI bots into the RongCloud IM platform and connecting them with Dify LLM services.


2. High-Level Architecture

Workflow:

  1. App Server
  • Manages bots, processes webhook callbacks, and receives bot messages.
  1. User Client
  • Sends user messages and receives bot responses.
  1. IM Server
  • Message Forwarding: Forwards messages to Dify based on callback types (e.g., dify_chat, dify_completion) and supports both streaming and non-streaming modes.

  • Response Handling and Session Management:

  • Streaming: Pushes incremental content from Dify in real time.

  • Non-streaming: Sends the complete message after receiving the full response.

  • Session Context: Stores conversation_id from the first interaction (valid for 24 hours). Subsequent messages use this ID to maintain multi-turn context.

  1. Dify
  • Receives the message, performs inference, and returns either streaming or complete text responses.

3. Integration and Deployment Guide

This section helps you deploy and configure the integration quickly, enabling you to experience intelligent bot interactions on RongCloud IM.

3.1 Prerequisites

Before integrating your bot, please ensure the following:

  • You have created an application on the RongCloud Developer Console and obtained a valid App Key and App Secret.
  • Dify is deployed (either self-hosted or via a cloud service).

3.2 Supported Callback Types

Callback types determine how bots interact with different platforms or systems. Currently supported types include:

TypeDescription
webhookCustom callback via webhook, suitable for flexible integration
dify_chatConnects to Dify’s “Chat Assistant” mode for building multi-turn bots
dify_completionConnects to Dify’s “Text Completion” mode for generative applications
dify_chatflowConnects to Dify’s “Chatflow” mode for flow-based conversational design

3.3 Integration Steps

  1. Create a Dify App: Create an app in Dify and obtain the API key.
  2. Create a Real User: Create a real user account to interact with the bot.
  3. Configure the Bot and Callback Address: Register your bot and set up the message callback.
  4. Verify Integration: Send a private message from the real user to the bot and confirm the response from Dify.
  5. Verify Multi-Turn Conversation: Continue sending messages from the same user to the bot and check if context is preserved.

⚠️ Note: RongCloud API calls require authentication. Use the provided script to generate credentials.


Step 1: Create a Dify App

Message assistants connect using the dify_chatflow mode, which supports memory-based multi-turn workflows.

You can check the full DSL config example: dify-chatflow-dsl.yml


Step 2: Create a Real User

curl -X POST "https://api.rong-api.com/v3/bot/create.json" \
  -H "App-Key: YOUR_APP_KEY" \
  -H "Nonce: YOUR_NONCE" \
  -H "Timestamp: YOUR_TIMESTAMP" \
  -H "Signature: YOUR_SIGNATURE" \
  -H "Content-Type: application/x-www-form-urlencoded" \
  -d "userId=LoDld8izA"

Step 3: Configure Bot and Callback Address

Depending on your scenario, choose between:

  • Streaming mode: Best for long or incremental responses, offering a smoother user experience.
  • Non-streaming mode: Best when responses are shown only after completion.
curl -X POST "https://api.rong-api.com/v3/bot/create.json" \
  -H "App-Key: YOUR_APP_KEY" \
  -H "Nonce: YOUR_NONCE" \
  -H "Timestamp: YOUR_TIMESTAMP" \
  -H "Signature: YOUR_SIGNATURE" \
  -H "Content-Type: application/json" \
  -d '{
    "userId": "bot-test004",
    "name": "Message Assistant",
    "type": "Message AI",
    "profileUrl": "https://cdn.jsdelivr.net/gh/microsoft/fluentui-emoji/assets/Robot/3D/robot_3d.png",
    "integrations": [
        {
            "type": "webhook",
            "callbackUrl": "https://yourserver.com/callback",
            "objectNames":["RC:TxtMsg"],
            "events":["message:private"]
        },
        {
            "type": "dify_chatflow",
            "callbackUrl": "https://api.dify.ai/v1",
            "stream": true,
            "auth": {
                "apiKey": "YOUR_DIFY_API_KEY"
            }
        }
    ],
    "metadata": {
        "version": 1
    }
}'

Step 4: Verify Integration

Send a message from the real user created in step 2:

curl -X POST "https://api.rong-api.com/message/private/publish.json" \
  -H "App-Key: YOUR_APP_KEY" \
  -H "Nonce: YOUR_NONCE" \
  -H "Timestamp: YOUR_TIMESTAMP" \
  -H "Signature: YOUR_SIGNATURE" \
  -H "Content-Type: application/x-www-form-urlencoded" \
  --data-urlencode "fromUserId=BesqX1FTg33" \
  --data-urlencode "toUserId=bot-001" \
  --data-urlencode "objectName=RC:TxtMsg" \
  --data-urlencode 'content={"content":"Can you give me a few AI use case ideas?","extra":""}'

Demo screenshots from Sealtalk APP:


Step 5: Verify Multi-Turn Conversations

Send multiple messages from the same user to the same bot and check if the context is preserved.

The Dify log shows 4 messages, confirming that multi-turn conversation context is successfully maintained within the same session.


4. Use Cases

4.1 Message Assistant: Enable smart Q&A, task execution, content generation

  • Knowledge Q&A powered by knowledge base or LLM
  • Content generation requests (e.g., “Write an apology email”)
  • Translation requests (e.g., “Translate this to English”)
  • Instruction requests that trigger system actions (e.g., “Create a ticket”)
  • FAQ automation based on user intent parsing

4.2 Companion Bot: Create personalized, emotionally intelligent chatbots

  • Natural casual conversations to fulfill daily social interaction needs
  • Role simulation (e.g., friend, therapist, virtual idol) to enhance engagement
  • Emotion-aware responses and empathetic interaction
  • Combine with custom character settings (e.g., “AI Partner”, “Career Coach”) for immersive experiences

5. Best Practices

5.1 Use Metadata to Personalize Bot Context

When creating bots, you can pass custom metadata for the creator. This metadata will be included in message callbacks and forwarded to Dify. It can be used for:

  • Prompt variable substitution
  • Contextual customization
  • Flow orchestration

5.2 Configure Separate Bots and Dify Apps per Scenario

It is recommended to create separate bots and Dify apps for each business use case (e.g., Q&A, translation, tools, companionship). Assign specific prompts to each bot for better targeting and improved user experience.


6. Utility Scripts

6.1 Generate RongCloud HTTP Signature

import hashlib
import time
import random


def generate_rongcloud_signature(app_secret, nonce=None, timestamp=None):
    """
    Generate RongCloud HTTP request signature.

    Parameters:
        app_secret: Your RongCloud App Secret
        nonce: Optional random string
        timestamp: Optional timestamp

    Returns:
        Dictionary with nonce, timestamp, and signature
    """
    if nonce is None:
        nonce = ''.join(random.choices('0123456789abcdefghijklmnopqrstuvwxyz', k=6))

    if timestamp is None:
        timestamp = str(int(time.time()))

    signature_str = app_secret + nonce + timestamp
    signature = hashlib.sha1(signature_str.encode('utf-8')).hexdigest()

    return {
        'nonce': nonce,
        'timestamp': timestamp,
        'signature': signature
    }


if __name__ == '__main__':
    app_secret = 'YOUR_APP_SECRET'
    signature_data = generate_rongcloud_signature(app_secret)

    print("Generated RongCloud Signature:")
    print(f"Nonce: {signature_data['nonce']}")
    print(f"Timestamp: {signature_data['timestamp']}")
    print(f"Signature: {signature_data['signature']}")

Conclusion

Thank you for exploring this guide on integrating RongCloud IM PaaS with Dify LLM services. This powerful combination simplifies the AI bot development process by reducing technical complexity, while providing a robust callback mechanism and native multi-turn support.

Whether you’re building a knowledge bot, a content generation tool, or a personalized companion chatbot, RongCloud and Dify together offer a stable and efficient solution.

As AI technology continues to evolve, we will keep enhancing platform compatibility and provide more tools and documentation. We welcome your feedback to help shape the future of intelligent dialogue systems.

Wishing you success on your development journey and in your projects!