diff --git a/Samples/WhatsAppBusinessCloudAPI.Web/Controllers/WhatsAppNotificationController.cs b/Samples/WhatsAppBusinessCloudAPI.Web/Controllers/WhatsAppNotificationController.cs index 7e871bb..57075fa 100644 --- a/Samples/WhatsAppBusinessCloudAPI.Web/Controllers/WhatsAppNotificationController.cs +++ b/Samples/WhatsAppBusinessCloudAPI.Web/Controllers/WhatsAppNotificationController.cs @@ -30,6 +30,7 @@ public class WhatsAppNotificationController : ControllerBase private List quickReplyButtonMessage; private List replyButtonMessage; private List listReplyButtonMessage; + private List flowMessage; public WhatsAppNotificationController(ILogger logger, IWhatsAppBusinessClient whatsAppBusinessClient, IOptions whatsAppConfig, IWebHostEnvironment webHostEnvironment) @@ -383,6 +384,25 @@ public async Task ReceiveWhatsAppTextMessage([FromBody] dynamic m Message = "List Reply Message Received" }); } + + if (getInteractiveType.Equals("nfm_reply")) // Flow message rceived + { + var flowMessageReceived = JsonConvert.DeserializeObject(Convert.ToString(messageReceived)) as FlowMessageReceived; + flowMessage = new List(flowMessageReceived.Messages); + _logger.LogInformation(JsonConvert.SerializeObject(flowMessage, Formatting.Indented)); + _logger.LogInformation($"User flow message sent: {flowMessage.SingleOrDefault().Interactive.NfmReply.Body}\n{flowMessage.SingleOrDefault().Interactive.NfmReply.ResponseJson}"); + + MarkMessageRequest markMessageRequest = new MarkMessageRequest(); + markMessageRequest.MessageId = flowMessage.SingleOrDefault().Id; + markMessageRequest.Status = "read"; + + await _whatsAppBusinessClient.MarkMessageAsReadAsync(markMessageRequest); + + return Ok(new + { + Message = "Flow Message Received" + }); + } } } return Ok(); diff --git a/Samples/WhatsAppBusinessCloudAPI.Web/WhatsAppBusinessCloudAPI.Web.csproj b/Samples/WhatsAppBusinessCloudAPI.Web/WhatsAppBusinessCloudAPI.Web.csproj index 6379a8a..4ac2183 100644 --- a/Samples/WhatsAppBusinessCloudAPI.Web/WhatsAppBusinessCloudAPI.Web.csproj +++ b/Samples/WhatsAppBusinessCloudAPI.Web/WhatsAppBusinessCloudAPI.Web.csproj @@ -8,7 +8,7 @@ - + diff --git a/WhatsappBusiness.CloudApi/Webhook/FlowMessageReceived.cs b/WhatsappBusiness.CloudApi/Webhook/FlowMessageReceived.cs new file mode 100644 index 0000000..7399257 --- /dev/null +++ b/WhatsappBusiness.CloudApi/Webhook/FlowMessageReceived.cs @@ -0,0 +1,62 @@ +using Newtonsoft.Json; +using System.Collections.Generic; + +namespace WhatsappBusiness.CloudApi.Webhook +{ + public class FlowMessageReceived + { + [JsonProperty("messages")] + public List Messages { get; set; } + } + + public class FlowMessage + { + [JsonProperty("context")] + public FlowContext Context { get; set; } + + [JsonProperty("from")] + public string From { get; set; } + + [JsonProperty("id")] + public string Id { get; set; } + + [JsonProperty("type")] + public string Type { get; set; } + + [JsonProperty("interactive")] + public FlowInteractive Interactive { get; set; } + + [JsonProperty("timestamp")] + public string Timestamp { get; set; } + } + + public class FlowContext + { + [JsonProperty("from")] + public string From { get; set; } + + [JsonProperty("id")] + public string Id { get; set; } + } + + public class FlowInteractive + { + [JsonProperty("type")] + public string Type { get; set; } + + [JsonProperty("nfm_reply")] + public NfmReply NfmReply { get; set; } + } + + public partial class NfmReply + { + [JsonProperty("name")] + public string Name { get; set; } + + [JsonProperty("body")] + public string Body { get; set; } + + [JsonProperty("response_json")] + public string ResponseJson { get; set; } + } +} diff --git a/WhatsappBusiness.CloudApi/WhatsappBusiness.CloudApi.csproj b/WhatsappBusiness.CloudApi/WhatsappBusiness.CloudApi.csproj index 6906633..fa45a9b 100644 --- a/WhatsappBusiness.CloudApi/WhatsappBusiness.CloudApi.csproj +++ b/WhatsappBusiness.CloudApi/WhatsappBusiness.CloudApi.csproj @@ -12,19 +12,19 @@ https://github.com/gabrieldwight/Whatsapp-Business-Cloud-Api-Net enable latest - 1.0.35 + 1.0.36 - + - +