I am trying to implement Twilio voice calls in C#.
I have the following code which initiate a call.
var accoutnSid = "XXXXXXXXXXXXX";
var authToken = "XXXXXXXXXXXXX";
TwilioClient.Init(accoutnSid, authToken);
var to = new PhoneNumber("tonumber");
var from = new PhoneNumber("fromnumber");
var response = new VoiceResponse();
response.Say("Hello, Please speak");
response.Gather(
input: new []{Gather.InputEnum.Speech}.ToList(),
timeout: 2,
action: new Uri("https://mywebapi.com/version/v0/routecalls/twilioresponse"),
method: Twilio.Http.HttpMethod.Post);
response.Say("Thanks for your input");
var call = CallResource.Create(to: to, from: from, twiml: response.ToString());
When the user is done talking, per Twilio documentation below end point is called
https://mywebapi.com/version/v0/routecalls/twilioresponse.
The code at the end point is below.
using Microsoft.AspNetCore.Mvc;
using Twilio.AspNet.Common;
using Twilio.AspNet.Core;
using Twilio.TwiML;
namespace webapi.Controllers;
[ApiController]
public class TwilioCallsController : TwilioController
{
public TwiMLResult twilioresponse(VoiceRequest request)
{
Console.WriteLine(request.ToString());
var response = new VoiceResponse();
response.Say("You selected sales. Good for you!");
return TwiML(response);
}
}
The first part of the setup works fine, but when the user is done talking and I call the API end point, I get the following error at the API end point. 415 Unsupported Media Type
Could someone please let me know what am i doing wring.