Skip to main content

Overview

LangFlow is a powerful tool for building AI chatbots using a drag-and-drop interface. This integration allows you to connect your LangFlow chatbots to Pactory and monetize them.

Prerequisites

  • A LangFlow agent deployed and running
  • Your LangFlow API endpoint URL
  • Your LangFlow API key

Integration Steps

1

LangFlow Agent Setup

  • Basic Setup
  • Advanced Setup
For a basic setup, you need to create a custom LangFlow component for the highlighted input block on the screenshot, and paste in the following code.LangFlow Setup Instructions
import json
from langflow.base.io.text import TextComponent
from langflow.io import MultilineInput, Output
from langflow.schema.message import Message
from langflow.utils.constants import MESSAGE_SENDER_AI, MESSAGE_SENDER_USER
from langflow.field_typing import BaseChatMessageHistory
from langchain.memory import ChatMessageHistory


class ParseInputComponent(TextComponent):
    display_name = "Parse Input"
    description = "Parse JSON input containing userId, redirectUrl, messages, and uploads into separate outputs."
    icon = "type"
    name = "ParseInput"

    inputs = [
        MultilineInput(
            name="input_value",
            display_name="JSON Input",
            info="JSON containing userId, redirectUrl, messages array, and uploads array.",
        ),
    ]
    
    outputs = [
        Output(display_name="User ID", name="user_id", method="get_user_id"),
        Output(display_name="Redirect URL", name="redirect_url", method="get_redirect_url"),
        Output(display_name="Chat History", name="chat_history", method="get_chat_history"),
        Output(display_name="Uploads", name="uploads", method="get_uploads"),
    ]

    def parse_json(self):
        try:
            if not hasattr(self, '_parsed_data'):
                self._parsed_data = json.loads(self.input_value)
            return self._parsed_data
        except json.JSONDecodeError:
            self.status = "Invalid JSON input"
            return {"userId": "default", "redirectUrl": "", "messages": [], "uploads": []}

    def get_user_id(self) -> Message:
        data = self.parse_json()
        user_id = data.get("userId", "default")
        return Message(text=user_id)

    def get_redirect_url(self) -> Message:
        data = self.parse_json()
        redirect_url = data.get("redirectUrl", "")
        return Message(text=redirect_url)

    def get_chat_history(self) -> Message:
        data = self.parse_json()
        formatted_messages = []
        
        for msg in data.get("messages", []):
            text = msg.get("text", "")
            sender = msg.get("sender", "HUMAN")
            
            if sender.upper() in ["AI", MESSAGE_SENDER_AI]:
                formatted_messages.append(f"AI: {text}")
            else:
                formatted_messages.append(f"User: {text}")

        chat_history = "\n".join(formatted_messages)
        return Message(text=chat_history)

    def get_uploads(self) -> Message:
        data = self.parse_json()
        uploads = data.get("uploads", [])
        return Message(text=json.dumps(uploads)) 
2

Access Integration

From your Pactory dashboard, go to “Add New Agent” and select “LangFlow”
3

Configure Basic Settings

Fill in the standard agent configuration fields (name, description, etc.)
4

Configure Integration

Enter your LangFlow-specific configuration:
  • API endpoint URL (required)
  • API key (required)
5

Test Connection

Send a test message to verify the integration is working properly
6

Share your agent and get paid based on usage!

I