This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MessageInput | |
{ | |
public string Phone { get; set; } // Phone number to send to. | |
public string Message { get; set; } // The message to send | |
public string SmsKey { get; set; } // Key unique to each message | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[FunctionName("SendMessageStarter")] | |
public static async Task<HttpResponseMessage> Run( | |
[HttpTrigger(AuthorizationLevel.Anonymous, "post")] | |
HttpRequestMessage req, | |
[OrchestrationClient] DurableOrchestrationClient starter, | |
ILogger log) | |
{ | |
var input = await req.Content.ReadAsAsync<MessageInput>(); | |
var orchestrationId = await starter.StartNewAsync("O_SendMessage", input); | |
return starter.CreateCheckStatusResponse(req, orchestrationId); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[FunctionName("O_SendMessage")] | |
public static async Task SendMessageOrchestrator( | |
[OrchestrationTrigger] DurableOrchestrationContextBase context, | |
ILogger log) | |
{ | |
MessageInput messageInput = context.GetInput<MessageInput>(); | |
string smsKey = await context.CallActivityAsync<string>("A_SaveTwilioMapping", context.InstanceId); | |
messageInput.SmsKey = smsKey; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[FunctionName("A_SaveTwilioMapping")] | |
public static async Task<string> SaveTwilioMapping( | |
[ActivityTrigger] string orchestrationId, | |
[Table(MessageMapping.TableName)] IAsyncCollector<MessageMapping> table) | |
{ | |
var mapping = new MessageMapping | |
{ | |
PartitionKey = "Sms", | |
RowKey = Guid.NewGuid().ToString("N"), | |
OrchestrationId = orchestrationId |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MessageMapping | |
{ | |
public const string TableName = "SentMessages"; | |
public string PartitionKey { get; set; } | |
public string RowKey { get; set; } | |
public string OrchestrationId { get; set; } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[FunctionName("A_SendTwilioText")] | |
public static async Task SendTwilioText( | |
[ActivityTrigger] MessageInput input, | |
[TwilioSms] IAsyncCollector<CreateMessageOptions> message, | |
ILogger log) | |
{ | |
log.LogWarning($"Twilio Activity. Sending message"); | |
CreateMessageOptions smsText = new CreateMessageOptions(new PhoneNumber(input.Phone)) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[FunctionName("TwilioHandler")] | |
public static async Task<HttpResponseMessage> Webhook( | |
[HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "TwilioHandler/{id}")] | |
HttpRequestMessage req, | |
[OrchestrationClient] DurableOrchestrationClient client, | |
[Table(MessageMapping.TableName, "Sms", "{id}")] MessageMapping mapping, | |
ILogger log) | |
{ | |
var content = await req.Content.ReadAsStringAsync(); | |
var formBody = ParseForm(content); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[FunctionName("ColdStarter")] | |
public static async Task Run( | |
[TimerTrigger("* */15 * * * *")]TimerInfo myTimer, | |
ILogger log) | |
{ | |
var client = new HttpClient(); | |
await client.GetAsync(Environment.GetEnvironmentVariable("FunctionUrl")); | |
log.LogInformation($"Pinged Function at: {DateTime.Now}"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[assembly: WebJobsStartup(typeof(Startup))] | |
namespace YOUR.NAMESPACE | |
{ | |
internal class Startup : IWebJobsStartup | |
{ | |
public void Configure(IWebJobsBuilder builder) | |
{ | |
builder.AddDependencyInjection(ConfigureServices); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[FunctionName("A_SendMail")] | |
public static async Task<string> SendMail( | |
[ActivityTrigger] object input, | |
[Inject]ISendGridClient client, | |
ILogger log) | |
{} |
OlderNewer