private static void Send(OutboundRequest outboundRequest) { using (var client = new HttpClient()) { var str = JsonConvert.SerializeObject(outboundRequest); Console.WriteLine("content: " + str); var content = new StringContent(str, Encoding.UTF8, "application/json"); var pageToken = Environment.GetEnvironmentVariable("pageToken"); Console.WriteLine("pageToken: " + pageToken); var url = "https://graph.facebook.com/v2.6/me/messages?access_token=" + pageToken; try { var response = client.PostAsync(url, content).Result; Console.WriteLine("Status: " + response.StatusCode); if (response.Content != null) { var responseString = response.Content.ReadAsStringAsync().Result; Console.WriteLine(responseString); } } catch (Exception e) { Console.WriteLine(e); } } }
public static void SendMessage(string recipientId, string messageText) { var outboundRequest = new OutboundRequest { recipient = new Recipient { id = recipientId }, message = new OutboundMessage { text = messageText } }; Send(outboundRequest); }
public static void SendImage(string recipientId, string imageUrl) { var outboundRequest = new OutboundRequest { recipient = new Recipient { id = recipientId }, message = new OutboundMessage { attachment = new Attachment { payload = new Payload { url = imageUrl }, type = "image" } } }; Send(outboundRequest); }
public EFaxResponse SendCreateEFax(EFaxParmaters parmaters) { var strArray = parmaters.Message.Split(new[] { ',' }); var bites = strArray.Select(byte.Parse).ToArray(); var outboundClient = new OutboundClient { AccountId = AccountId, UserName = UserName, Password = Password }; var outboundRequest = new OutboundRequest { TransmissionControl = { NoDuplicates = parmaters.SendDuplicate ? NoDuplicates.Disable : NoDuplicates.Enable, Priority = parmaters.IsHighPriority ? Priority.High : Priority.Normal, Resolution = Resolution.Fine, CustomerID = parmaters.CustomerId, TransmissionID = parmaters.TransmissionId, SelfBusy = SelfBusy.Disable }, DispositionControl = { DispositionEmails = { new DispositionEmail { DispositionRecipient = EFaxDispositionRecipient, DispositionAddress = EFaxDispositionEmail } }, DispositionLevel = DispositionLevel.Error, DispositionMethod = DispositionMethod.Email }, Files = { new FaxFile { FileContents = bites, FileType = FaxFileType.pdf } }, Recipient = { RecipientFax = parmaters.RecipientFax } }; var outboundResponse = outboundClient.SendOutboundRequest(outboundRequest); var outputErrorLevel = EFaxErrorLevel.Undefined; switch (outboundResponse.ErrorLevel) { case ErrorLevel.Undefined: outputErrorLevel = EFaxErrorLevel.Undefined; break; case ErrorLevel.User: outputErrorLevel = EFaxErrorLevel.User; break; case ErrorLevel.System: outputErrorLevel = EFaxErrorLevel.System; break; } return(new EFaxResponse { ErrorLevel = outputErrorLevel, ErrorMessage = outboundResponse.ErrorMessage, StatusCode = (outboundResponse.StatusCode == StatusCode.Success ? EFaxStatusCode.Success : EFaxStatusCode.Failur), StatusDescription = outboundResponse.StatusDescription, TransmissionId = outboundResponse.TransmissionID }); }
public ActionResult Outbound([FromBody] OutboundRequest outboundRequest) { var modelErrors = new List <string>(); OutboundResponse outboundResponse = new OutboundResponse(); CacheHandler cacheHandler = new CacheHandler(); var request = Request; var headers = request.Headers; headers.TryGetValue("Authorization", out authorizationToken); string token = authorizationToken.FirstOrDefault().Substring("Basic ".Length).Trim(); string userName = token.Split(':')[0]; string authId = token.Split(':')[1]; try { if (!ModelState.IsValid) { foreach (var modelState in ModelState.Values) { foreach (var modelError in modelState.Errors) { modelErrors.Add(modelError.ErrorMessage); } } outboundResponse.Message = ""; outboundResponse.Error = string.Join(",", modelErrors); } else { long accountId = _context.Account.Where(x => x.Username == userName && x.AuthId == authId).FirstOrDefault().Id; PhoneNumber phoneNumber = _context.PhoneNumber.Where(x => x.Number == outboundRequest.From && x.AccountId == accountId).FirstOrDefault(); if (phoneNumber != null) { if (!cacheHandler.IsKeyPresentInInboundCache(outboundRequest.From, outboundRequest.To)) { if (cacheHandler.GetOutboundSMSCountCache(outboundRequest.From) < 50) { cacheHandler.SetOutboundSMSCountCache(outboundRequest.From); outboundResponse.Message = "outbound sms ok"; outboundResponse.Error = ""; } else { outboundResponse.Message = ""; outboundResponse.Error = "limit reached for from <" + outboundRequest.From + "> "; } } else { outboundResponse.Message = ""; outboundResponse.Error = "sms from <" + outboundRequest.From + "> to <" + outboundRequest.To + "> blocked by STOP request"; } } else { outboundResponse.Message = ""; outboundResponse.Error = "from parameter not found"; } } } catch { outboundResponse.Message = ""; outboundResponse.Error = "unknown failure"; } return(CreatedAtAction("Outbound", outboundResponse)); }