-
Notifications
You must be signed in to change notification settings - Fork 206
/
Copy pathTwilioSamples.cs
102 lines (94 loc) · 4.39 KB
/
TwilioSamples.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
using Microsoft.Azure.WebJobs;
using Newtonsoft.Json.Linq;
using Twilio.Rest.Api.V2010.Account;
using Twilio.Types;
namespace ExtensionsSample.Samples
{
// To use the TwilioSamples:
// 1. Configure your Twilio Account SID via the 'AzureWebJobsTwilioAccountSid' App Setting or Environment variable
// 2. Configure your Twilio Auth Token via the 'AzureWebJobsTwilioAuthToken' App Setting or Environment variable
// 3. Add typeof(TwilioSamples) to the SamplesTypeLocator in Program.cs
public static class TwilioSamples
{
/// <summary>
/// Demonstrates declaratively SMS message properties with parameter binding
/// to message properties.
/// </summary>
public static void ProcessOrder_Declarative(
[QueueTrigger(@"samples-orders")] Order order,
[TwilioSms(
From = "{StorePhoneNumber}",
Body = "{CustomerName}, we've received your order ({OrderId}) and have begun processing it!")]
out CreateMessageOptions messageOptions)
{
// You can set additional message properties here
messageOptions = new CreateMessageOptions(new PhoneNumber(order.CustomerPhoneNumber));
}
/// <summary>
/// Demonstrates imperatively setting SMS message properties inline in the function.
/// </summary>
[Disable]
public static void ProcessOrder_Imperative(
[QueueTrigger(@"samples-orders")] Order order,
[TwilioSms] out CreateMessageOptions messageOptions)
{
messageOptions = new CreateMessageOptions(new PhoneNumber(order.StorePhoneNumber))
{
From = new PhoneNumber(order.StorePhoneNumber),
Body = string.Format("{0}, we've received your order ({1}) and have begun processing it!", order.CustomerName, order.OrderId)
};
}
/// <summary>
/// Demonstrates the JObject binding (the JObject will be converted into an message)
/// </summary>
[Disable]
public static void ProcessOrder_JObject(
[QueueTrigger(@"samples-orders")] Order order,
[TwilioSms] out JObject message)
{
message = new JObject()
{
{ "From", order.StorePhoneNumber },
{ "To", order.CustomerPhoneNumber },
{ "Body", string.Format("{0}, we've received your order ({1}) and have begun processing it!", order.CustomerName, order.OrderId) }
};
}
/// <summary>
/// Demonstrates the IAsyncCollector binding. This works with <see cref="JObject"/>
/// or <see cref="CreateMessageOptions"/>. Using IAsyncCollector is also a way to conditionally
/// send messages from a function.
/// </summary>
[Disable]
public static void ProcessOrder_MessageAsyncCollector(
[QueueTrigger(@"samples-orders")] Order order,
[TwilioSms] IAsyncCollector<CreateMessageOptions> messages)
{
var messageOptions = new CreateMessageOptions(new PhoneNumber(order.CustomerPhoneNumber))
{
From = new PhoneNumber(order.StorePhoneNumber),
Body = string.Format("{0}, we've received your order ({1}) and have begun processing it!", order.CustomerName, order.OrderId)
};
messages.AddAsync(messageOptions);
}
/// <summary>
/// Demonstrates the IAsyncCollector binding. This works with <see cref="JObject"/>
/// or <see cref="CreateMessageOptions"/>. Using IAsyncCollector is also a way to conditionally
/// send messages from a function.
/// </summary>
[Disable]
public static void ProcessOrder_JObjectAsyncCollector(
[QueueTrigger(@"samples-orders")] Order order,
[TwilioSms] IAsyncCollector<JObject> messages)
{
var message = new JObject()
{
{ "From", order.StorePhoneNumber },
{ "To", order.CustomerPhoneNumber },
{ "Body", string.Format("{0}, we've received your order ({1}) and have begun processing it!", order.CustomerName, order.OrderId) }
};
messages.AddAsync(message);
}
}
}