> ## Documentation Index
> Fetch the complete documentation index at: https://langchain-zh.cn/llms.txt
> Use this file to discover all available pages before exploring further.

# Twilio 集成

> 使用 LangChain Python 与 Twilio 工具集成。

本笔记本介绍了如何使用 [Twilio](https://www.twilio.com) API 包装器通过短信或 [Twilio 消息渠道](https://www.twilio.com/docs/messaging/channels) 发送消息。

Twilio 消息渠道支持与第三方消息应用程序的集成，并允许您通过 WhatsApp 商业平台 (GA)、Facebook Messenger (公共测试版) 和 Google 商务消息 (私有测试版) 发送消息。

## 设置

要使用此工具，您需要安装 Python Twilio 包 `twilio`

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
pip install -qU  twilio
```

您还需要设置一个 Twilio 账户并获取您的凭据。您需要您的账户字符串标识符 (SID) 和身份验证令牌。您还需要一个用于发送消息的号码。

您可以将这些作为命名参数 `account_sid`、`auth_token`、`from_number` 传递给 TwilioAPIWrapper，或者您可以设置环境变量 `TWILIO_ACCOUNT_SID`、`TWILIO_AUTH_TOKEN`、`TWILIO_FROM_NUMBER`。

## 发送短信

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
from langchain_community.utilities.twilio import TwilioAPIWrapper
```

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
twilio = TwilioAPIWrapper(
    #     account_sid="foo",
    #     auth_token="bar",
    #     from_number="baz,"
)
```

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
twilio.run("hello world", "+16162904619")
```

## 发送 WhatsApp 消息

您需要将 WhatsApp 商业账户与 Twilio 链接。您还需要确保用于发送消息的号码在 Twilio 上配置为 WhatsApp 启用发送者，并在 WhatsApp 上注册。

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
from langchain_community.utilities.twilio import TwilioAPIWrapper
```

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
twilio = TwilioAPIWrapper(
    #     account_sid="foo",
    #     auth_token="bar",
    #     from_number="whatsapp: baz,"
)
```

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
twilio.run("hello world", "whatsapp: +16162904619")
```

***

<div className="source-links">
  <Callout icon="edit">
    [Edit this page on GitHub](https://github.com/langchain-ai/docs/edit/main/src/i18n\zh-CN\oss\python\integrations\tools\twilio.mdx) or [file an issue](https://github.com/langchain-ai/docs/issues/new/choose).
  </Callout>

  <Callout icon="terminal-2">
    [Connect these docs](/use-these-docs) to Claude, VSCode, and more via MCP for real-time answers.
  </Callout>
</div>
