LangChain iMessage Integration — Add iMessage to LangChain Agents

Wrap Sendblue's REST API as a LangChain Tool and give your agents the ability to send iMessages. Build AI-powered messaging workflows with the framework you already use.

How to Connect LangChain + Sendblue

1

Get API Credentials

Sign up at dashboard.sendblue.com and grab your API key and secret. These go into your environment variables for secure access.

2

Create the Tool Wrapper

Write a LangChain Tool that calls Sendblue's REST API at https://api.sendblue.co/api/send-message. Use the @tool decorator or StructuredTool class to define input schema and execution logic.

3

Add to Your Agent

Pass the Sendblue tool to your LangChain agent alongside any other tools. The agent can now decide when to send an iMessage as part of its reasoning chain.

Example: Python Tool Wrapper

import requests
from langchain.tools import tool

@tool
def send_imessage(phone_number: str, message: str) -> str:
    """Send an iMessage to a phone number via Sendblue.
    Use E.164 format for the phone number (e.g. +15551234567)."""
    response = requests.post(
        "https://api.sendblue.co/api/send-message",
        headers={
            "sb-api-key-id": SENDBLUE_API_KEY,
            "sb-api-secret-key": SENDBLUE_API_SECRET,
            "Content-Type": "application/json",
        },
        json={"number": phone_number, "content": message},
    )
    return response.json()

Key Features

Standard Tool Pattern

Sendblue works as a standard LangChain Tool — no special adapters. Use @tool, StructuredTool, or BaseTool subclass. It fits into any agent type that supports tools.

Agent-Driven Messaging

Your LangChain agent decides when to text. It can reason about customer context, determine the right message, and send it — all within a single chain execution.

Chain Composition

Combine the Sendblue tool with other LangChain tools: look up a customer in your database, generate a personalized message with an LLM, then send it via iMessage. One chain, multiple steps.

Python & JavaScript

Sendblue's REST API is language-agnostic. Wrap it in langchain (Python) or langchain.js (TypeScript). The tool pattern is identical in both SDKs.

Delivery Tracking

Add a second tool that checks message status via Sendblue's API. Your agent can verify delivery before moving on, or retry if a message fails.

Automatic SMS Fallback

Sendblue detects iMessage availability. Your LangChain agent does not need to handle routing — Sendblue sends blue bubbles to iPhones and SMS to Android automatically.

Why LangChain + iMessage?

LangChain is the most popular framework for building LLM-powered agents. By adding Sendblue as a tool, you give those agents the ability to communicate through iMessage — the highest-engagement messaging channel available in the US.

There is no native LangChain integration for Sendblue. Instead, you wrap Sendblue's REST API as a custom tool. This is the standard LangChain pattern for external APIs, and it takes about 15 lines of code (see example above).

Once connected, your agents can send appointment reminders, order confirmations, follow-up messages, and support responses — all over iMessage. Combine it with retrieval tools, database lookups, and other APIs to build complete customer communication workflows.

For production deployments, pair the LangChain agent with Sendblue's webhook system to handle incoming replies. When a customer texts back, the webhook fires, your application passes the message to the agent, and the agent responds — creating an autonomous conversation loop. This works alongside Sendblue's native CRM integrations for HubSpot, Salesforce, and GoHighLevel.

Get started with LangChain + Sendblue

Free sandbox, no credit card required. Add iMessage to your LangChain agents in minutes.

Get API Access

Frequently Asked Questions

Does LangChain have a native Sendblue integration?

No. There is no built-in LangChain integration for Sendblue. You wrap Sendblue's REST API as a custom LangChain Tool using the @tool decorator or the StructuredTool class. This is a standard LangChain pattern for adding external API capabilities to agents.

Can a LangChain agent send and receive iMessages?

Yes. Define a send-message tool that POSTs to Sendblue's API, and a receive-messages tool that fetches incoming messages. Your LangChain agent can then send iMessages and process replies as part of its reasoning chain.

Which LangChain agent types work with Sendblue?

Any LangChain agent that supports tools — including ReAct agents, OpenAI function-calling agents, and custom agent executors. The Sendblue tool is a standard LangChain Tool object, so it works anywhere tools are accepted.

What programming languages are supported?

Sendblue's REST API works with any language. For LangChain specifically, you can use the Python SDK (langchain) or the JavaScript/TypeScript SDK (langchain.js). The tool wrapper pattern is the same in both.