-
Notifications
You must be signed in to change notification settings - Fork 0
/
SendLocation.cs
47 lines (44 loc) · 2 KB
/
SendLocation.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
using System;
using System.IO;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using Imhere.Data;
using Twilio.Rest.Api.V2010.Account;
using Twilio.Types;
namespace ImHere.Functions
{
public static class SendLocation
{
[FunctionName("SendLocation")]
public static async Task<IActionResult> Run([HttpTrigger(AuthorizationLevel.Anonymous,
"get", "post",
Route = null)]HttpRequest req,
[TwilioSms(AccountSidSetting = "TwilioAccountSid",
AuthTokenSetting = "TwilioAuthToken",
From = "+19073181762")] ICollector<CreateMessageOptions> messages,
ILogger log)
{
log.LogInformation("C# HTTP trigger function processed a request.");
string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
PostData data = JsonConvert.DeserializeObject<PostData>(requestBody);
string url = $"https://www.google.com/maps/search/?api=1&query={data.Latitude},{data.Longitude}";
log.LogInformation($"URL created - {url}");
foreach (string toNo in data.ToNumbers)
{
PhoneNumber number = new PhoneNumber(toNo);
CreateMessageOptions message = new CreateMessageOptions(number)
{
Body = $"I'm here! {url}"
};
log.LogInformation($"Creating SMS message to {message.To}, message is '{message.Body}'.");
messages.Add(message);
}
return new OkResult();
}
}
}