public int addLog(Models.MessageResponse thisMessage, int leadId) { int leadLogId = -1; Models.OlgarsMessageLog appLog = new Models.OlgarsMessageLog(); appLog.LeadId = leadId; appLog.UserId = 0; appLog.DateAdded = DateTime.Now; appLog.AddedBy = "Server Notify Job"; //Now the passed items appLog.MessageCode = thisMessage.errorCode; appLog.MessageError = thisMessage.error; appLog.MessageStatus = thisMessage.messageStatus; appLog.MessageId = thisMessage.messageId; appLog.MessageTo = thisMessage.to; appLog.MessageText = thisMessage.messageText; leadLogId = addMessageLog(appLog); return(leadLogId); }
// GET: Message public async Task <ActionResult> Index(string user_key, string type, string content) { Client = new DirectLineClient(directLineSecret); if (Session["cid"] as string != null) { this.Conversation = Client.Conversations.ReconnectToConversation((string)Session["CONVERSTAION_ID"]); } else { this.Conversation = Client.Conversations.StartConversation(); Session["cid"] = Conversation.ConversationId; } Activity userMessage = new Activity { From = new ChannelAccount(fromUser), Type = ActivityTypes.Message, Text = content }; await Client.Conversations.PostActivityAsync(this.Conversation.ConversationId, userMessage); //메시지를 받는 부분 string watermark = null; while (true) { var activitySet = await Client.Conversations.GetActivitiesAsync(Conversation.ConversationId, watermark); watermark = activitySet?.Watermark; var activities = from x in activitySet.Activities where x.From.Id == botId select x; Models.Message message = new Models.Message(); Models.MessageResponse messageResponse = new Models.MessageResponse(); messageResponse.message = message; foreach (Activity activity in activities) { message.text = activity.Text + "--" + this.Conversation.ConversationId; } return(Json(messageResponse, JsonRequestBehavior.AllowGet)); //return View(); } }
public static Models.MessageResponse DirectLineToKakao(IList <Activity> activities) { if (activities == null || activities.Count <= 0) { return(null); } var msg = new Models.MessageResponse(); // 여러개의 Activity foreach (var activity in activities) { if (activity.Type != ActivityTypes.Message) { continue; } if (msg.message == null) { msg.message = new Message(); } // 텍스트 메시지를 누적 시킴 msg.message.text += "\n" + activity.Text; if (activity.Attachments != null && activity.Attachments.Count > 0) { foreach (Attachment attachment in activity.Attachments) { switch (attachment.ContentType) { case "image/png": case "image/jpeg": if (msg.message.photo == null) { msg.message.photo = new Photo { url = attachment.ContentUrl, width = 100, height = 100 }; } break; case "application/vnd.microsoft.card.hero": var heroCard = JsonConvert.DeserializeObject <HeroCard>(attachment.Content.ToString()); if (!string.IsNullOrEmpty(heroCard.Text.Trim())) { msg.message.text += "\n\n" + heroCard.Text; } if (heroCard.Images != null) { var img = heroCard.Images.FirstOrDefault(); if (msg.message == null) { msg.message = new Message(); } msg.message.photo = new Photo { url = img.Url, width = 1000, height = 1000 }; } if (heroCard.Buttons != null) { var herobutton = heroCard.Buttons.Where(x => x.Type == ActionTypes.OpenUrl).FirstOrDefault(); if (herobutton != null) { if (msg.message == null) { msg.message = new Message(); } msg.message.message_button = new MessageButton { label = herobutton.Title, url = herobutton.Value.ToString() }; } var heroactionbutton = heroCard.Buttons.Where(x => x.Type == ActionTypes.ImBack).ToList(); if (msg.keyboard == null) { msg.keyboard = new Keyboard { buttons = new string[] { }, type = "buttons" }; List <string> buttons = new List <string>(); foreach (var actionbutton in heroactionbutton) { buttons.Add(actionbutton.Value.ToString()); } msg.keyboard.buttons = buttons.ToArray(); } } break; } } } } return(msg); }
public static Models.MessageResponse DirectLineToKakao(Activity activity) { if (activity == null) { return(null); } var msg = new Models.MessageResponse(); if (activity.Type == ActivityTypes.Message) { if (msg.message == null) { msg.message = new Message(); } // 텍스트 메시지 msg.message.text = activity.Text; // 이미지 if (activity.Attachments != null && activity.Attachments.Count > 0) { foreach (Attachment attachment in activity.Attachments) { switch (attachment.ContentType) { case "image/png": case "image/jpeg": if (msg.message.photo == null) { msg.message.photo = new Photo { url = attachment.ContentUrl }; } break; case "application/vnd.microsoft.card.hero": var heroCard = JsonConvert.DeserializeObject <HeroCard>(attachment.Content.ToString()); var img = heroCard.Images.FirstOrDefault(); if (img != null && msg.message.photo == null) { msg.message.photo = new Photo { url = img.Url }; } if (heroCard.Buttons != null) { List <string> buttons = new List <string>(); foreach (CardAction action in heroCard.Buttons) { if (action.Type == ActionTypes.OpenUrl) { if (msg.message.message_button == null) { msg.message.message_button = new MessageButton { label = action.Title, url = action.Value.ToString() }; } } else if (action.Type == ActionTypes.PostBack) { buttons.Add(action.Value.ToString()); } } if (msg.keyboard == null) { msg.keyboard = new Keyboard { buttons = new string[] { }, type = "buttons" }; msg.keyboard.buttons = buttons.ToArray(); } } break; } } } } return(msg); }
public static Models.MessageResponse DirectLineToKakao(Activity activity) { if (activity == null) { return(null); } var msg = new Models.MessageResponse(); if (activity.Type == ActivityTypes.Message) { if (msg.message == null) { msg.message = new Message(); } // 텍스트 메시지 msg.message.text = activity.Text; // 이미지 if (activity.Attachments != null && activity.Attachments.Count > 0) { foreach (Attachment attachment in activity.Attachments) { switch (attachment.ContentType) { case "image/png": case "image/jpeg": // activity는 attachment가 배열로 여러개가 오지만 Kakao는 한개만 가능. // 따라서 처음 하나만 보여지는 걸로 ... if (msg.message.photo == null) { // width, height를 주개 되어 있는데 줄 방법이 다운로드하고 열어서 헤더를 열어봐야 하지만 // http://stackoverflow.com/questions/30054517/get-image-dimensions-directly-from-an-url-c-sharp // 우선 설정하지 않고 보내면 카카오톡이 어찌 표시해주겠지 ... msg.message.photo = new Photo { url = attachment.ContentUrl }; } break; case "application/vnd.microsoft.card.hero": var heroCard = JsonConvert.DeserializeObject <HeroCard>(attachment.Content.ToString()); var img = heroCard.Images.FirstOrDefault(); if (img != null && msg.message.photo == null) { msg.message.photo = new Photo { url = img.Url }; } if (heroCard.Buttons != null) { List <string> buttons = new List <string>(); foreach (CardAction action in heroCard.Buttons) { if (action.Type == ActionTypes.OpenUrl) { if (msg.message.message_button == null) { msg.message.message_button = new MessageButton { label = action.Title, url = action.Value.ToString() }; } } else if (action.Type == ActionTypes.PostBack) { buttons.Add(action.Value.ToString()); } } if (msg.keyboard == null) { msg.keyboard = new Keyboard { buttons = new string[] { }, type = "buttons" }; msg.keyboard.buttons = buttons.ToArray(); } } break; } } } } return(msg); }
public static Models.MessageResponse DirectLineToKakao(IList <Activity> activities) { if (activities == null || activities.Count <= 0) { return(null); } var msg = new Models.MessageResponse(); // 여러개의 Activity foreach (var activity in activities) { if (activity.Type != ActivityTypes.Message) { continue; } if (msg.message == null) { msg.message = new Message(); } // 텍스트 메시지를 누적 시킴 msg.message.text += "\n" + activity.Text; if (activity.Attachments != null && activity.Attachments.Count > 0) { foreach (Attachment attachment in activity.Attachments) { switch (attachment.ContentType) { case "image/png": case "image/jpeg": // activity는 attachment가 배열로 여러개가 오지만 Kakao는 한개만 가능. // 따라서 처음 하나만 보여지는 걸로 ... if (msg.message.photo == null) { // width, height를 주개 되어 있는데 줄 방법이 다운로드하고 열어서 헤더를 열어봐야 하지만 // http://stackoverflow.com/questions/30054517/get-image-dimensions-directly-from-an-url-c-sharp // 우선 설정하지 않고 보내면 카카오톡이 어찌 표시해주겠지 ... msg.message.photo = new Photo { url = attachment.ContentUrl, width = 100, height = 100 }; } break; case "application/vnd.microsoft.card.hero": var heroCard = JsonConvert.DeserializeObject <HeroCard>(attachment.Content.ToString()); // hero 카드의 텍스트가 있다면 text 뒤에 붙여줌 if (!string.IsNullOrEmpty(heroCard.Text.Trim())) { msg.message.text += "\n\n" + heroCard.Text; } // 이미지가 여러개면 모두 표시를 못해줌. // 처음한개만 가져옴. width hegith 없는데 어떻게 표시될지? if (heroCard.Images != null) { var img = heroCard.Images.FirstOrDefault(); if (msg.message == null) { msg.message = new Message(); } msg.message.photo = new Photo { url = img.Url, width = 1000, height = 1000 }; } // 액션 버튼도 한개만 표시 가능함. OpenUrl 처음 한개만. if (heroCard.Buttons != null) { var herobutton = heroCard.Buttons.Where(x => x.Type == ActionTypes.OpenUrl).FirstOrDefault(); if (herobutton != null) { if (msg.message == null) { msg.message = new Message(); } msg.message.message_button = new MessageButton { label = herobutton.Title, url = herobutton.Value.ToString() }; } var heroactionbutton = heroCard.Buttons.Where(x => x.Type == ActionTypes.ImBack).ToList(); if (msg.keyboard == null) { msg.keyboard = new Keyboard { buttons = new string[] { }, type = "buttons" }; List <string> buttons = new List <string>(); foreach (var actionbutton in heroactionbutton) { buttons.Add(actionbutton.Value.ToString()); } msg.keyboard.buttons = buttons.ToArray(); } } break; } } } } return(msg); }
//This function is in charge of converting the data into a json array and sending it to the rest sending controller. public static string SendSMS(int leadId, string Token, Dictionary <string, string> Params) { Params["to"] = CreateRecipientList(Params["to"]); string JsonArray = JsonConvert.SerializeObject(Params, Formatting.None); JsonArray = JsonArray.Replace("\\\"", "\"").Replace("\"[", "[").Replace("]\"", "]"); string errMesg = ""; Models.MessageResponse mesgResponse = new Models.MessageResponse(); string ReturnBody = CallClickATell(Token, JsonArray); var rootObject = JsonConvert.DeserializeObject <ClickAtellResponse>(ReturnBody); if (rootObject != null) { string apiMessage = rootObject.messages[0].apiMessageId; string errorCode = ""; string errorDesc = ""; if (apiMessage == null) { apiMessage = "Error Response from Service Provider"; } mesgResponse.messageId = apiMessage; mesgResponse.messageText = Params["content"].ToString(); mesgResponse.to = Params["to"].ToString(); if (rootObject.messages[0].errorCode != null) { errorCode = rootObject.messages[0].errorCode.ToString(); } mesgResponse.errorCode = errorCode; if (rootObject.messages[0].errorDescription != null) { errorDesc = rootObject.messages[0].errorDescription.ToString(); } mesgResponse.errorDescription = errorDesc; mesgResponse.error = errorDesc; string errStatus = rootObject.messages[0].accepted.ToString(); mesgResponse.messageStatus = errStatus; errMesg = apiMessage + " " + errorCode + " " + errorDesc + " " + errStatus; } else { mesgResponse.messageId = "error"; mesgResponse.errorCode = "error"; mesgResponse.errorDescription = "error"; mesgResponse.error = "error"; mesgResponse.messageStatus = "error"; mesgResponse.messageText = Params["content"].ToString(); mesgResponse.to = Params["to"].ToString(); } Controllers.MessageOperations msgOps = new Controllers.MessageOperations(); msgOps.addLog(mesgResponse, leadId); return(errMesg); }