/** * Sends an SMS */ static SMSSent sendSMS(String[] auth, SendSMS sendSMS) { using (var wb = new WebClient()) { wb.Headers.Set(HttpRequestHeader.ContentType, "application/json"); wb.Headers.Add("user_key", auth[0]); wb.Headers.Add("Session_key", auth[1]); String json = JsonConvert.SerializeObject(sendSMS); var sentSMSBody = wb.UploadString(BASEURL + "sms", "POST", json); SMSSent sentSMSResponse = JsonConvert.DeserializeObject <SMSSent>(sentSMSBody); return(sentSMSResponse); } }
public static IActionResult Run([HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)] HttpRequest req, TraceWriter log) { try { log.Info("C# HTTP trigger function processed a request."); string requestBody = new StreamReader(req.Body).ReadToEnd(); dynamic data = JsonConvert.DeserializeObject(requestBody.ToString()); string password = data.password; string sender = data.sender; string[] recipient = new String[] { }; string message = data.message; string message_type = data.message_type; recipient = data.recipient.ToObject <string[]>(); if (password != correct_password) { return((ActionResult) new OkObjectResult("Bad request - Wrong Password")); } String[] auth = authenticate("skebbyuser", "skebbypassword"); SendSMS sendSMSRequest = new SendSMS(); sendSMSRequest.message = message; sendSMSRequest.recipient = recipient; if (message_type == null) { sendSMSRequest.message_type = "SI"; } else { sendSMSRequest.message_type = message_type; } if (sendSMSRequest.message_type == "GP" || sendSMSRequest.message_type == "TI") { sendSMSRequest.sender = sender; } else { sendSMSRequest.sender = ""; } SMSSent smsSent = sendSMS(auth, sendSMSRequest); if ("OK".Equals(smsSent.result)) { log.Info("SMS successfully sent!"); return((ActionResult) new OkObjectResult("SMS successfully sent!")); } } catch (Exception ex) { return(new BadRequestObjectResult("Bad Request - " + ex)); } return(new BadRequestObjectResult("Bad Request")); }