Skip to content

Commit

Permalink
Fix #99
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrieldwight committed Aug 14, 2024
1 parent c41951a commit d2c3479
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public class WhatsAppNotificationController : ControllerBase
private List<QuickReplyButtonMessage> quickReplyButtonMessage;
private List<ReplyButtonMessage> replyButtonMessage;
private List<ListReplyButtonMessage> listReplyButtonMessage;
private List<FlowMessage> flowMessage;

public WhatsAppNotificationController(ILogger<WhatsAppNotificationController> logger, IWhatsAppBusinessClient whatsAppBusinessClient,
IOptions<WhatsAppBusinessCloudApiConfig> whatsAppConfig, IWebHostEnvironment webHostEnvironment)
Expand Down Expand Up @@ -383,6 +384,25 @@ public async Task<IActionResult> ReceiveWhatsAppTextMessage([FromBody] dynamic m
Message = "List Reply Message Received"
});
}

if (getInteractiveType.Equals("nfm_reply")) // Flow message rceived
{
var flowMessageReceived = JsonConvert.DeserializeObject<FlowMessageReceived>(Convert.ToString(messageReceived)) as FlowMessageReceived;
flowMessage = new List<FlowMessage>(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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<ItemGroup>
<PackageReference Include="CsvHelper" Version="33.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="8.0.7" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="8.0.8" />
</ItemGroup>

<ItemGroup>
Expand Down
62 changes: 62 additions & 0 deletions WhatsappBusiness.CloudApi/Webhook/FlowMessageReceived.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using Newtonsoft.Json;
using System.Collections.Generic;

namespace WhatsappBusiness.CloudApi.Webhook
{
public class FlowMessageReceived
{
[JsonProperty("messages")]
public List<FlowMessage> 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; }
}
}
6 changes: 3 additions & 3 deletions WhatsappBusiness.CloudApi/WhatsappBusiness.CloudApi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@
<RepositoryUrl>https://github.com/gabrieldwight/Whatsapp-Business-Cloud-Api-Net</RepositoryUrl>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
<Version>1.0.35</Version>
<Version>1.0.36</Version>
</PropertyGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net8.0' or '$(TargetFramework)' == 'netstandard2.1'">
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Http" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Http.Polly" Version="8.0.7" />
<PackageReference Include="Microsoft.Extensions.Http.Polly" Version="8.0.8" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net6.0' or '$(TargetFramework)' == 'netstandard2.0'">
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.1" />
<PackageReference Include="Microsoft.Extensions.Http" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Http.Polly" Version="6.0.32" />
<PackageReference Include="Microsoft.Extensions.Http.Polly" Version="6.0.33" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net7.0'">
Expand Down

0 comments on commit d2c3479

Please sign in to comment.