【发布时间】:2022-01-19 02:19:02
【问题描述】:
我是一名 Twilio 新手,正在尝试开发一个与自动电话树交互的 C# 应用程序。问题是电话树的开头每次都有些不同,所以我没有尝试自动化所有不同的排列,而是在电话树、应用程序和我的个人电话号码之间创建电话会议。我希望接听我的电话,与树进行交互,直到我到达“可自动化”部分,然后挂断我的电话,让应用程序从那时起与电话会议交互。
到目前为止,我已经能够使用两个 CallResource.Create() 调用成功创建会议。我目前面临的问题是,当我将 CallResource.Update() 与树 Sid 一起使用时,一旦执行 Twiml,它就会挂起该调用资源,我不知道为什么。对我的电话号码的呼叫仍在进行,但无论我向树呼叫资源发送什么 twiml,它都会挂断。
- 有关如何在不挂断的情况下使用一些 twiml 更新呼叫的任何帮助
- 或者,也许有更好的方法来完成我正在寻找的所有事情?
感谢任何建议!下面是我正在使用的代码
谢谢, 肖恩
public void MakeCall()
{
var accountSid = ConfigurationManager.AppSettings["TwilioAccountSid"];
var authToken = ConfigurationManager.AppSettings["TwilioAuthToken"];
var mePhoneNumber = ConfigurationManager.AppSettings["MyPhoneNumber"];
var treePhoneNumber = ConfigurationManager.AppSettings["TreePhoneNumber"];
var conferenceName = "treeNavigate" + Guid.NewGuid();
TwilioClient.Init(accountSid, authToken);
Twimlet treeConferenceTwimlet = new Twimlet();
treeConferenceTwimlet.Endpoint = "conference";
treeConferenceTwimlet.Parameters.Add("Name", conferenceName);
treeConferenceTwimlet.Parameters.Add("Message", "Hi Tree");
Twimlet meConferenceTwimlet = new Twimlet();
meConferenceTwimlet.Endpoint = "conference";
meConferenceTwimlet.Parameters.Add("Name", conferenceName);
meConferenceTwimlet.Parameters.Add("Message", "Hi Me");
var meCall = CallResource.Create(
to: new PhoneNumber(mePhoneNumber),
from: new PhoneNumber(mePhoneNumber),
url: new Uri(meConferenceTwimlet.GetFormattedURL()));
var treeCall = CallResource.Create(
to: new PhoneNumber(treePhoneNumber),
from: new PhoneNumber(mePhoneNumber),
url: new Uri(treeConferenceTwimlet.GetFormattedURL()));
CallResource.Update(
pathSid: treeCall.Sid,
twiml: new Twilio.Types.Twiml("<Response><Say>I can hear this on the conference but then it hangs up right after</Say></Response>"));
}
public class Twimlet
{
private String baseUrl = "http://twimlets.com/";
public Dictionary<String, String> Parameters { get; set; }
public String Endpoint { get; set; }
public Twimlet()
{
this.Parameters = new Dictionary<string, string>();
}
public String GetFormattedURL()
{
return String.Format(
"{0}{1}?{2}",
this.baseUrl,
this.Endpoint,
String.Join("&", this.Parameters.Select(x => String.Format("{0}={1}", HttpUtility.UrlEncode(x.Key), HttpUtility.UrlEncode(x.Value)))));
}
}
【问题讨论】:
标签: twilio twilio-twiml twimlet