Skip to content

Instantly share code, notes, and snippets.

@gsuttie
Created September 16, 2020 17:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gsuttie/92ed20b1cd1f2e0d87e3e2e090ce4708 to your computer and use it in GitHub Desktop.
Save gsuttie/92ed20b1cd1f2e0d87e3e2e090ce4708 to your computer and use it in GitHub Desktop.
retrudurablefunction3times
[FunctionName("A_MakeCall2")]
public static string MakeCall2([ActivityTrigger] CallInfo callInfo, [Table("MadeCalls2", "AzureWebJobStorage")] out CallDetails calldetails, ILogger log)
{
log.LogWarning($"MakeCall {callInfo.Numbers}");
var madeCallId = Guid.NewGuid().ToString("N");
calldetails = new CallDetails
{
PartitionKey = "MadeCalls",
RowKey = madeCallId,
OrchestrationId = callInfo.InstanceId
};
string accountSid = Environment.GetEnvironmentVariable("accountSid");
string authToken = Environment.GetEnvironmentVariable("authToken");
TwilioClient.Init(accountSid, authToken);
// ***********************************************************************************************************
//TODO figure out how best to call this and loop thru the numbers instead of hardcoding the first number below
// ***********************************************************************************************************
//var to = new PhoneNumber(callInfo.Numbers[0]);
//var to = new PhoneNumber(callInfo.NumberCalled);
var from = new PhoneNumber(Environment.GetEnvironmentVariable("twilioDemoNumber"));
log.LogWarning($"InstanceId {callInfo.InstanceId}");
var myCallInfo = callInfo;
foreach (var number in myCallInfo.Numbers)
{
for (int retryCount = 1; retryCount <= myCallInfo.Attempts; retryCount++)
{
log.LogWarning($"The {number} has been called {retryCount} times");
// TODO be careful with the code at the end of this string as it changes
//var statusCallbackUri = new Uri(string.Format(Environment.GetEnvironmentVariable("statusCallBackUrl"), madeCallId));
var statusCallbackUri = new Uri(string.Format(Environment.GetEnvironmentVariable("statusCallBackUrl"), callInfo.InstanceId));
log.LogWarning($"statusCallbackUri {statusCallbackUri}");
var statusCallbackEvent = new List<string> { "answered" };
var to = new PhoneNumber(number);
log.LogWarning($"About to make a call to {to} from {from}.");
var call = CallResource.Create(
to,
from,
url: new Uri("http://demo.twilio.com/docs/voice.xml"),
statusCallback: statusCallbackUri,
statusCallbackMethod: Twilio.Http.HttpMethod.Post,
statusCallbackEvent: statusCallbackEvent);
}
}
//await Task.Delay(100);
return madeCallId;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment