Using https://dify.ai/ as the Agent Builder with ConversationRelay. This code-sample uses conversationrelay-bridge npmjs package.
For local development, make sure you have Node and ngrok installed.
- Clone this repo
- Run
npm install
. Thencp .env.example .env
and set up the variables. We will get the Flowise values from the next step - Modify
handlers/twiml.ts
to change the default greeting message or any other changes you want to ConversationRelay. All available attributes can be found on TwiML™ Voice: - Run
npm run dev
to start the dev server. Expose your local server to the internet usingngrok http 8080
- Visit Twilio Console page to purchase a number. Then configure the Incoming Webhook to point to
ngrokDomain/twiml
- Visit https://dify.ai/ and sign up for an account
- Create a new Chatflow and configure it as you see fit.
- Click on your avatar in the top right corner and select
Settings
thenModel Provider
. Setup the model(s) you want to use and provide the their API keys. - Go back to home page and select
Tools
from the top menu bar. Search forTwilio
and selectSend Message
. Set up the credentials for your Twilio account. - Go to
Studio
from the top menu and create clickCreate from blank
and selectChatflow
. Give it a name and description. - Delete the
LLM
component. Add anode
using+
and selectAgent
. ConnectStart -> Agent -> Answer
. - Select
Start
and add a custominput field
. ChooseShort Text
and set the name asfrom
and mark it asrequired
.
- Select
Agent
:-
For
Agentic Strategy
, selectAgent -> ReAct
-
For
Model
, choose your favorite model from the dropdown. -
Add
Twilio - Send Message
to the list of available tools. -
Add a friendly instruction for the system prompt.
-
Inside the
Query
add the following:Query: {{start.sys.query}} Customer Number: {{start.x.from}} ConversationId: {{start.sys.conversation_id}}
-
Enable
memory
-
- Now
publish
your changes. - Select
API Access
from the left panel, and click onAPI Key
on the top right corner. Create a new service key and save it to.env
asDIF_API_KEY
.
You are now ready to call your number!
We suggest using Fly.IO to host your application. It supports long-running WebSocket connections and is free (when you signup, you have to add your credit card, but you can deploy free servers for testing purposes).
This repo includes the cofiguration for easily deploying the application to Fly.IO. All the configurations are located in the fly.toml
file.
- Sign up for Fly.IO and install/setup the CLI.
- Create a new Fly App:
fly apps create cr-dify
- Grab the domain name of your newly created Fly app and update your local
.env
with theDOMAIN
value. - Setup the secrets:
fly secrets import < .env
- Deploy the application:
fly deploy
- Scale down instances to 1 (if you want to keep this free) using
fly scale count 1
- View the logs:
fly logs
You can now set the Incoming Webhook of your Twilio number to point to DOMAIN/twiml
.