{ "cells": [ { "attachments": {}, "cell_type": "markdown", "id": "dc23c48e", "metadata": {}, "source": [ "# Twilio\n", "\n", "This notebook goes over how to use the [Twilio](https://www.twilio.com) API wrapper to send a message through SMS or [Twilio Messaging Channels](https://www.twilio.com/docs/messaging/channels).\n", "\n", "Twilio Messaging Channels facilitates integrations with 3rd party messaging apps and lets you send messages through WhatsApp Business Platform (GA), Facebook Messenger (Public Beta) and Google Business Messages (Private Beta)." ] }, { "attachments": {}, "cell_type": "markdown", "id": "c1a33b13", "metadata": {}, "source": [ "## Setup\n", "\n", "To use this tool you need to install the Python Twilio package `twilio`" ] }, { "cell_type": "code", "execution_count": 1, "id": "98b544b9", "metadata": {}, "outputs": [], "source": [ "# !pip install twilio" ] }, { "attachments": {}, "cell_type": "markdown", "id": "f7e883ae", "metadata": {}, "source": [ "You'll also need to set up a Twilio account and get your credentials. You'll need your Account String Identifier (SID) and your Auth Token. You'll also need a number to send messages from.\n", "\n", "You can either pass these in to the TwilioAPIWrapper as named parameters `account_sid`, `auth_token`, `from_number`, or you can set the environment variables `TWILIO_ACCOUNT_SID`, `TWILIO_AUTH_TOKEN`, `TWILIO_FROM_NUMBER`." ] }, { "attachments": {}, "cell_type": "markdown", "id": "36c133be", "metadata": {}, "source": [ "## Sending an SMS" ] }, { "cell_type": "code", "execution_count": 1, "id": "54bf5afd", "metadata": {}, "outputs": [], "source": [ "from langchain.utilities.twilio import TwilioAPIWrapper" ] }, { "cell_type": "code", "execution_count": 2, "id": "31f8f382", "metadata": {}, "outputs": [], "source": [ "twilio = TwilioAPIWrapper(\n", " # account_sid=\"foo\",\n", " # auth_token=\"bar\",\n", " # from_number=\"baz,\"\n", ")" ] }, { "cell_type": "code", "execution_count": null, "id": "5009d763", "metadata": {}, "outputs": [], "source": [ "twilio.run(\"hello world\", \"+16162904619\")" ] }, { "attachments": {}, "cell_type": "markdown", "id": "de022dc9", "metadata": {}, "source": [ "## Sending a WhatsApp Message" ] }, { "attachments": {}, "cell_type": "markdown", "id": "a594d0bc", "metadata": {}, "source": [ "You'll need to link your WhatsApp Business Account with Twilio. You'll also need to make sure that the number to send messages from is configured as a WhatsApp Enabled Sender on Twilio and registered with WhatsApp." ] }, { "cell_type": "code", "execution_count": null, "id": "94508aa0", "metadata": {}, "outputs": [], "source": [ "from langchain.utilities.twilio import TwilioAPIWrapper" ] }, { "cell_type": "code", "execution_count": null, "id": "e4b81750", "metadata": {}, "outputs": [], "source": [ "twilio = TwilioAPIWrapper(\n", " # account_sid=\"foo\",\n", " # auth_token=\"bar\",\n", " # from_number=\"whatsapp: baz,\"\n", ")" ] }, { "cell_type": "code", "execution_count": null, "id": "1181041b", "metadata": {}, "outputs": [], "source": [ "twilio.run(\"hello world\", \"whatsapp: +16162904619\")" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.11.3" } }, "nbformat": 4, "nbformat_minor": 5 }