Skip to content

Ask the docs

Answers come only from these docs and are written by an AI model (Gemini), so check the linked pages. Your question is not kept. Do not include personal details or keys.

LangChain

LangChain · LangChain WhatsApp · LangChain Telegram bot · LangChain iMessage · LangChain chatbot WhatsApp API · LangChain messaging integration

Connect a LangChain model or chain to your messaging conversations.

Connect your LangChain model or chain to the Messaging API. Each incoming message starts a run, and Flow delivers its streamed answer as chat bubbles.

// npm install @flow-engineer/messaging @langchain/openai
import { ChatOpenAI } from "@langchain/openai";
import { FlowMessaging, contentText } from "@flow-engineer/messaging";
const flow = new FlowMessaging();
const model = new ChatOpenAI({ model: "gpt-4.1-mini" });
for await (const event of flow.events.stream({ types: ["message.received"] })) {
const stream = await model.stream([
["system", "You are the assistant for Asha's Bakery. Answer in short messages."],
["human", contentText(event.data.message.content)],
]);
await event.conversation.reply(stream); // reads each chunk's content
}
  • Any runnable whose .stream() yields message chunks works with reply(): chat models, prompt.pipe(model) chains, and chains ending in a string output parser.
  • The Python version answers in the webhook response (one round trip). Flow waits 10 seconds for the answer, so this suits fast chains; for slower ones answer {} at once and send later with POST /v0/conversations/{conversation_id}/basic. Flow sends the text exactly as written (it renders no markdown), so ask the model for plain text; the reply goes out as one message, so keep it within the channel’s text limit (4096 characters on Telegram). See Events and webhooks.
  • Keep chat history per conversation.id, or read it from GET /v0/conversations/{conversation_id}/messages.
  • To see each turn’s model and tool calls and get every reply graded, send this agent’s traces to Flow Observe: Traces from agent frameworks.

examples/langchain on GitHub.