private async Task <string> NotifyRaffleWinner(RaffleEntry entry) { var msg = await MessageResource.FetchAsync( entry.MessageSid, _accountSid); var response = await MessageResource.CreateAsync( msg.From, from : msg.To, body : @"You've won the latest raffle. Visit the Twilio booth to pick up your prize. If you can't email [email protected]"); _notificationSid = response.Sid; using (var httpClient = new HttpClient()) { var data = new FormUrlEncodedContent(new[] { new KeyValuePair <string, string>("winner", msg.From.ToString()), new KeyValuePair <string, string>("raffleSid", LatestRaffle.Sid), new KeyValuePair <string, string>("prize", LatestRaffle.Prize.Name) }); var httpResponse = await httpClient.PostAsync("https://hooks.zapier.com/hooks/catch/3191324/o3o1bt1/", data); httpResponse.EnsureSuccessStatusCode(); } return(_notificationSid); }
public static async Task <MessageResource> GetMessageAsync(ITwilioRestClient client, string messageSid, string accountSid) { var options = new FetchMessageOptions(messageSid) { PathAccountSid = accountSid }; return(await MessageResource.FetchAsync(options, client)); }
private async Task RemoveDuplicateEntries() { var flaggedEntries = new List <RaffleEntry>(); foreach (var entry in LatestRaffle.Entries) { var recipient = (await MessageResource.FetchAsync( entry.MessageSid)).From; if (flaggedEntries.Any(num => string.Equals(num.ToString(), recipient.ToString(), StringComparison.CurrentCultureIgnoreCase))) { flaggedEntries.Add(entry); } } LatestRaffle.Entries = LatestRaffle.Entries.Except(flaggedEntries).ToList(); }
private async Task NotifyRaffleReEntrants() { // TODO: Replace individual SMS messages with Notification Service await RemoveDuplicateEntries(); await Task.Run(() => Parallel.ForEach(LatestRaffle.Entries, async entry => { var resource = await MessageResource.FetchAsync(entry.MessageSid); var url = new Uri($"https://corey.ngrok.io/images/{LatestRaffle.Prize.ImageUrl}"); await MessageResource.CreateAsync( resource.From, from: new PhoneNumber(resource.To), body: $"Greetings from Twilio. Looks like you didn't win the last raffle but don't worry. We've re-entered you into the next one to win this prize: {LatestRaffle.Prize.Name}. Good luck and keep an eye out to see if you've won the prize", mediaUrl: new List <Uri> { url }); })); }
public async Task UpdateAsync() { var text = await MessageResource.FetchAsync(_sid); }
public async System.Threading.Tasks.Task UpdateAsync() { var call = await MessageResource.FetchAsync(APIKeys.sID); SetMessage(call); }
public async Task UpdateAsync() { var call = await MessageResource.FetchAsync(m_sid); SetMessage(call); }
public async Task UpdateAsync() { var message = await MessageResource.FetchAsync(m_sid); SetMessage(message); }