https://retellai.com/?utm_source=discord&utm_medium=seo logo
i have connected retell with n8n and twilio
# ❓・ai-evy-support
f
@AI Evy i have connected retell with n8n and twilio. retell takes calles from customer and n8n saves some data to CRM and sends sms to customer thorugh twilio with a case number. I want to get this case number back in retell as well real time, so the AI agent can tell that to the customer on call in addition to n8n sending it on sms thorugh twilio. im using conversational flow agent. what are the steps i can do this?
a
Thanks for tagging me @faizaz_50459. I'll look through relevant sources and get back to you shortly.
​ To learn more, see the sources I considered: [[1] Voice API: Integrate Phone AI Agents with Your System | Retell AI](https://www.retellai.com/blog/how-to-integrate-phone-ai-agents-with-your-existing-api-systems) [[2] Conversation Flow Overview](https://docs.retellai.com/build/conversation-flow/overview) ​
### Answer To get the case number back to Retell AI in real-time so your AI agent can speak it to the customer, you'll need to use Custom Functions within your Conversation Flow agent [(1) ]() . Here's how to set this up: Step 1: Create a Custom Function in Retell AI - In your Retell AI Dashboard, navigate to your agent's settings - In the "Functions" section, click "+ Add" and select "Custom Function" - Define the function details: - **Name**: Use underscores (e.g.,
get_case_number
) - **Description**: Briefly describe the purpose (e.g., "Retrieve case number from CRM after creation") - **Specify the Endpoint URL**: Enter the URL where Retell AI will send POST requests to your n8n webhook - **Define Parameters**: Use JSON schema format to specify any parameters your function requires - **Configure Speech Behavior**: - Enable "Speak During Execution" if the agent should speak while the function runs (e.g., "Let me retrieve your case number") - Enable "Speak After Execution" if the agent should provide feedback after the function completes (e.g., "Your case number is...") Step 2: Set Up n8n Webhook to Return Case Number - Create an n8n webhook endpoint that your Custom Function will call - After your n8n workflow saves data to CRM and generates the case number, have it return the case number in JSON format to Retell - Verify the request's authenticity by checking the
X-Retell-Signature
header Step 3: Add Function Node to Your Conversation Flow - In your Conversation Flow, add a Function Node at the point where you want to retrieve the case number [(2) ]() - Configure this node to call your custom function - The function will execute when the agent reaches this node, call
ing your n8n webhook and receiving the case number back [(1) ]() Step 4: Use the Response in a Conversation Node - After the Function Node, add a Conversation Node where the agent can speak the case number to the customer [(2) ]() - The response from your custom function will be available for the agent to reference [(1) ]() This approach allows real-time data exchange between Retell AI and your n8n workflow, enabling your AI agent to speak the case number during the call while n8n also sends it via SMS through Twilio .
Feel free to tag @AI Evy with additional questions. I also appreciate feedback, it helps me improve.
f
you said After your n8n workflow saves data to CRM and generates the case number, have it return the case number in JSON format to Retell Verify the request's authenticity by checking the X-Retell-Signature header how do i do these 2 steps
@AI Evy you said After your n8n workflow saves data to CRM and generates the case number, have it return the case number in JSON format to Retell Verify the request's authenticity by checking the X-Retell-Signature header how do i do these 2 steps
a
Thanks for the follow-up, @faizaz_50459. I'll get back to you soon.
### Answer Here's how to complete those two steps in n8n: ## Step 1: Return the Case Number in JSON Format In your n8n workflow, after you save data to the CRM and generate the case number, configure your webhook response node to return JSON [(1) ]() [(2) ]() . The response should have a status code between 200-299 to indicate success . Your n8n webhook can return the case number in various formats (string, buffer, JSON object, or blob) , and all will be converted to string before sending to the LLM . For example:
Copy code
json
{
  "case_number": "CASE-12345"
}
[(1) ]() , [(2) ]() The function result is capped at 15000 characters [(1) ]() [(2) ]() . ## Step 2: Verify the X-Retell-Signature Header To verify that the request is coming from Retell, check the
X-Retell-Signature
header . The value is an encrypted request body using your secret key . In n8n, you can add a verification step using the Retell SDK. Here's example code for verification: Node.js example:
Copy code
javascript
import { Retell } from "retell-sdk";

this.app.post("/check-weather", async (req: Request, res: Response) => {
  if (
    !Retell.verify(
      JSON.stringify(req.body) ,
      process.env.RETELL_API_KEY,
      req.headers["x-retell-signature"] as string,
    )
  ) {
    console.error("Invalid signature") ;
    return;
  }
  const content = req.body;
  if (content.args.city === "New York") {
    return res.json("25f and sunny") ;
  } else {
    return res.json("20f and cloudy") ;
  }
}) ;
[(1) ]() Python example:
Copy code
python
from fastapi import FastAPI, Request
from fastapi.responses import JSONResponse
from retell import Retell

retell = Retell(api_key=os.environ["RETELL_API_KEY"])

@app.post("/check-weather")
async def check-weather(request: Request) :
  try:
    post_data = await request.json()
    valid_signature = retell.verify(
      json.dumps(post_data, separators=(",", ":") , ensure_ascii=False) ,
      api_key=str(os.environ["RETELL_API_KEY"]) ,
      signature=str(request.headers.get("X-Retell-Signature") ) ,
    )
    if not valid_signature:
      print(
        "Received Unauthorized",
        post_data["event"],
        post_data["data"]["call_id"],
      )
      return JSONResponse(status_code=401, content={"message": "Unauthorized"})
    
    args = post_data["args"]
    if args["city"] == "New York":
      return JSONResponse(status_code=200, content={"result": "25f and sunny"})
    else:
      return JSONResponse(status_code=200, content={"result": "20f and cloudy"})
  except Exception as err:
    print(f"Error in webhook: {err}")
    return JSONResponse(
      status_code=500, content={"message": "Internal Server Error"}
    )
You can also secure your server by only allowlisting Retell IP addresses:
100.20.5.228
. **
​ To learn more, see the sources I considered: [[1] Integrate any system with custom function](https://docs.retellai.com/build/single-multi-prompt/custom-function) [[2] Custom Function](https://docs.retellai.com/build/conversation-flow/custom-function) ​
Feel free to tag @AI Evy with additional questions. I also appreciate feedback, it helps me improve.
f
@AI Evy when i set up webhook response node in n8n and test the workflow it gives error that unused webhook response node in use
a
Thanks for the follow-up, @faizaz_50459. I'll get back to you soon.
### Answer --- Unfortunately, the error you're experiencing with the "unused webhook response node" in n8n is specific to n8n's workflow configuration, not Retell AI. The available sources don't cover n8n-specific troubleshooting. However, I can clarify what Retell AI expects from your webhook endpoint. When Retell AI calls your custom function, your n8n webhook needs to: 1. Accept POST requests from Retell AI [(1) ]() 2. Return a response with status code 200-299 to indicate success 3. Optionally verify the request using the
x-retell-signature
header [(2) ]() Here's the verification code that should work in your n8n setup: Node.js:
Copy code
javascript
import { Retell } from "retell-sdk";
import express, { Request, Response } from "express";
const app = express() ;
app.use(express.json() ) ;
app.post("/webhook", (req: Request, res: Response) => {
 if (
 !Retell.verify(
 JSON.stringify(req.body) ,
 process.env.RETELL_API_KEY,
 req.headers["x-retell-signature"] as string,
 )
 ) {
 console.error("Invalid signature") ;
 return;
 }
 const {event, call} = req.body;
 // process the webhook
 // Acknowledge the receipt of the event
 res.status(204) .send() ;
}) ;
Python:
Copy code
python
# install the sdk: <https://docs.retellai.com/get-started/sdk>
from retell import Retell
from flask import Flask, request, jsonify
app = Flask(__name__)
retell = Retell(api_key="YOUR_API_KEY")
@app.route("/webhook", methods=["POST"])
def webhook() :
 if not retell.verify(
 request.get_data(as_text=True) ,
 api_key="YOUR_API_KEY",
 signature=request.headers.get("X-Retell-Signature") ,
 ) :
 print("Invalid signature")
 return jsonify({"message": "Unauthorized"}) , 401
 event = request.json.get("event")
 call = request.json.get("call")
 # process the webhook
 return "", 204
For the n8n-specific "unused webhook response node" error, you'll need to consult n8n's documentation or their support channels, as this is outside Retell AI's scope. **
​ To learn more, see the sources I considered: [[1] Setup guide](https://docs.retellai.com/features/register-webhook) [[2] Secure the webhook](https://docs.retellai.com/features/secure-webhook) ​
Feel free to tag @AI Evy with additional questions. I also appreciate feedback, it helps me improve.
f
@AI Evy where can i find bearer token for retell for making http
a
Thanks for the follow-up, @faizaz_50459. I'll get back to you soon.
### Answer ### Answer The Retell API key (bearer token) is used for authentication when making HTTP requests to Retell AI [(1) ]() [(2) ]() . The format is "Bearer YOUR_API_KEY" . Where to find it: Your Retell API key can be found in your Retell AI Dashboard . How to use it: When making HTTP requests to Retell AI endpoints, include it in the Authorization header :
Copy code
Authorization: Bearer YOUR_RETELL_API_KEY
[(1) ]() , [(2) ]() Example usage in code:
Copy code
javascript
import Retell from 'retell-sdk';
const client = new Retell({
 apiKey: 'YOUR_RETELL_API_KEY',
}) ;
[(3) ]() The API key is required for all authenticated requests to the Retell AI API [(1) ]() [(2) ]() . --- **
​ To learn more, see the sources I considered: [[1] Update Agent](https://docs.retellai.com/api-references/update-agent) [[2] Create Agent](https://docs.retellai.com/api-references/create-agent) [[3] Create Chat](https://docs.retellai.com/api-references/create-chat) ​
Feel free to tag @AI Evy with additional questions. I also appreciate feedback, it helps me improve.