我正在寻求使用C#和Twilio API挂断所有呼叫的帮助,无论状态如何。像是一个废话的“杀手开关”。
我看到了这段用python编写的代码,想知道是否有人在C#中可以查看示例?
from twilio.rest import TwilioRestClient
from twilio.rest.resources import Call
ACCOUNT_SID = "YOUR_ACCOUNT_SID"
AUTH_TOKEN = "YOUR_AUTH_TOKEN"
client = TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN)
calls = client.calls.list(status=Call.IN_PROGRESS)
for c in calls:
c.hangup()
答案 0 :(得分:2)
您可以执行以下操作:
// Install the C# / .NET helper library from twilio.com/docs/csharp/install
using System;
using Twilio;
using Twilio.Rest.Api.V2010.Account;
class Program
{
static void Main(string[] args)
{
// Find your Account Sid and Token at twilio.com/console
const string accountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
const string authToken = "your_auth_token";
TwilioClient.Init(accountSid, authToken);
var call = CallResource.Update(
status: CallResource.UpdateStatusEnum.Completed,
pathSid: "CAe1644a7eed5088b159577c5802d8be38"
);
Console.WriteLine(call.To);
}
}
您可以将CallResource.Update(...)
方法包装在for循环中,并将有效调用列表作为参数传递。
您可以在此处找到更多信息:https://www.twilio.com/docs/voice/tutorials/how-to-modify-calls-in-progress-in-csharp#hanging-up-a-call-in-progress
答案 1 :(得分:0)
我想到了这个。至少不是很优雅,但是可以工作:
private void KillSwitch(string accountSid, string authToken)
{
TwilioClient.Init(accountSid, authToken);
var callsInProgress = CallResource.Read(status: CallResource.StatusEnum.InProgress);
var callsQueued = CallResource.Read(status: CallResource.StatusEnum.Queued);
var callsRinging = CallResource.Read(status: CallResource.StatusEnum.Ringing);
foreach (var call in callsQueued)
{
CallResource.Update(status: CallResource.UpdateStatusEnum.Completed, pathSid: call.Sid);
}
foreach (var call in callsInProgress)
{
CallResource.Update(status: CallResource.UpdateStatusEnum.Completed, pathSid: call.Sid);
}
foreach (var call in callsRinging)
{
CallResource.Update(status: CallResource.UpdateStatusEnum.Completed, pathSid: call.Sid);
}
}