-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e41c9e0
commit a6094c7
Showing
11 changed files
with
535 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
Samples/WhatsAppBusinessCloudAPI.Web/ViewModel/SendFlowMessageViewModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using Microsoft.AspNetCore.Mvc.Rendering; | ||
|
||
namespace WhatsAppBusinessCloudAPI.Web.ViewModel | ||
{ | ||
public class SendFlowMessageViewModel | ||
{ | ||
public string RecipientPhoneNumber { get; set; } | ||
public List<SelectListItem> FlowAction { get; set; } | ||
public string SelectedFlowAction { get; set; } | ||
public List<SelectListItem> Mode { get; set; } | ||
public string SelectedMode { get; set; } | ||
public string ScreenId { get; set; } | ||
public string FlowToken { get; set; } | ||
public string FlowId { get; set; } | ||
public string FlowButtonText { get; set; } | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
Samples/WhatsAppBusinessCloudAPI.Web/Views/Home/SendWhatsAppFlowMessage.cshtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
@model SendFlowMessageViewModel | ||
@{ | ||
ViewData["Title"] = "Send WhatsApp Flow Message Page"; | ||
ViewData["CurrentPage"] = "Send WhatsApp Flow Message"; | ||
Layout = "~/Views/Shared/AdminLTE/_AdminLayout.cshtml"; | ||
ViewData["ControllerName"] = nameof(HomeController).Replace("Controller", ""); | ||
ViewData["ActionName"] = nameof(HomeController.SendWhatsAppTextMessage); | ||
} | ||
|
||
<section class="content"> | ||
<div class="row"> | ||
<div class="col-12"> | ||
<div class="card card-info"> | ||
<div class="card-header"> | ||
<h3 class="card-title">Send WhatsApp Text Message</h3> | ||
</div> <!--/. card-header --> | ||
<!--Form start --> | ||
<form asp-action="SendWhatsAppTextMessage"> | ||
<div asp-validation-summary="ModelOnly" class="text-danger"></div> | ||
<div class="card-body"> | ||
<div class="form-group"> | ||
<label class="control-label">Recipient Phone Number</label> | ||
<input asp-for="RecipientPhoneNumber" class="form-control" /> | ||
<span asp-validation-for="RecipientPhoneNumber" class="form-control" /> | ||
</div> | ||
<div class="form-group"> | ||
<label class="control-label">Flow Action</label> | ||
<select class="form-control form-select form-select-lg mb-3" asp-for="SelectedFlowAction" asp-items="@Model.FlowAction"></select> | ||
<span asp-validation-for="SelectedFlowAction" class="form-control" /> | ||
</div> | ||
<div class="form-group"> | ||
<label class="control-label">Mode</label> | ||
<select class="form-control form-select form-select-lg mb-3" asp-for="SelectedMode" asp-items="@Model.Mode"></select> | ||
<span asp-validation-for="SelectedMode" class="form-control" /> | ||
</div> | ||
<div class="form-group"> | ||
<label class="control-label">Screen Name or Id</label> | ||
<input asp-for="ScreenId" class="form-control" /> | ||
<span asp-validation-for="ScreenId" class="form-control" /> | ||
</div> | ||
<div class="form-group"> | ||
<label class="control-label">Flow Token</label> | ||
<input asp-for="FlowToken" class="form-control" /> | ||
<span asp-validation-for="FlowToken" class="form-control" /> | ||
</div> | ||
<div class="form-group"> | ||
<label class="control-label">Flow Id</label> | ||
<input asp-for="FlowId" class="form-control" /> | ||
<span asp-validation-for="FlowId" class="form-control" /> | ||
</div> | ||
<div class="form-group"> | ||
<label class="control-label">Flow Button Text</label> | ||
<input asp-for="FlowButtonText" class="form-control" /> | ||
<span asp-validation-for="FlowButtonText" class="form-control" /> | ||
</div> | ||
</div> <!--/. card-body --> | ||
<div class="card-footer"> | ||
<button type="submit" name="submit" class="btn btn-primary">Send Message</button> | ||
</div> | ||
</form> | ||
</div> <!-- /.card --> | ||
</div> | ||
</div> | ||
</section> | ||
|
||
@section Scripts { | ||
@{ | ||
await Html.RenderPartialAsync("_ValidationScriptsPartial"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
117 changes: 117 additions & 0 deletions
117
WhatsappBusiness.CloudApi/Messages/Requests/FlowMessageRequest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
using Newtonsoft.Json; | ||
|
||
namespace WhatsappBusiness.CloudApi.Messages.Requests | ||
{ | ||
public class FlowMessageRequest | ||
{ | ||
[JsonProperty("recipient_type")] | ||
public string RecipientType { get; private set; } = "individual"; | ||
|
||
[JsonProperty("messaging_product")] | ||
public string MessagingProduct { get; private set; } = "whatsapp"; | ||
|
||
[JsonProperty("to")] | ||
public string To { get; set; } | ||
|
||
[JsonProperty("type")] | ||
public string Type { get; private set; } = "interactive"; | ||
|
||
[JsonProperty("interactive")] | ||
public FlowMessageInteractive Interactive { get; set; } | ||
} | ||
|
||
public class FlowMessageInteractive | ||
{ | ||
[JsonProperty("type")] | ||
public string Type { get; private set; } = "flow"; | ||
|
||
[JsonProperty("header")] | ||
public FlowMessageHeader Header { get; set; } | ||
|
||
[JsonProperty("body")] | ||
public FlowMessageBody Body { get; set; } | ||
|
||
[JsonProperty("footer")] | ||
public FlowMessageFooter Footer { get; set; } | ||
|
||
[JsonProperty("action")] | ||
public FlowMessageAction Action { get; set; } | ||
} | ||
|
||
public class FlowMessageAction | ||
{ | ||
[JsonProperty("name")] | ||
public string Name { get; private set; } = "flow"; | ||
|
||
[JsonProperty("parameters")] | ||
public FlowMessageParameters Parameters { get; set; } | ||
} | ||
|
||
public class FlowMessageParameters | ||
{ | ||
[JsonProperty("flow_message_version")] | ||
public string FlowMessageVersion { get; private set; } = "3"; | ||
|
||
[JsonProperty("flow_token")] | ||
public string FlowToken { get; set; } | ||
|
||
[JsonProperty("flow_id")] | ||
public string FlowId { get; set; } | ||
|
||
[JsonProperty("flow_cta")] | ||
public string FlowCta { get; set; } | ||
|
||
[JsonProperty("flow_action")] | ||
public string FlowAction { get; set; } | ||
|
||
[JsonProperty("flow_action_payload")] | ||
public FlowActionPayload FlowActionPayload { get; set; } | ||
|
||
[JsonIgnore] | ||
public bool IsInDraftMode { get; set; } | ||
|
||
[JsonProperty("mode", NullValueHandling = NullValueHandling.Ignore)] | ||
public string Mode { get; set; } | ||
|
||
public bool ShouldSerializeMode() | ||
{ | ||
// Only to be used for sending flows that have draft mode do not set this property when sending published flow messages | ||
return IsInDraftMode; | ||
} | ||
|
||
public bool ShouldSerializeFlowActionPayload() | ||
{ | ||
return FlowAction.Equals("navigate", System.StringComparison.OrdinalIgnoreCase); | ||
} | ||
} | ||
|
||
public class FlowActionPayload | ||
{ | ||
[JsonProperty("screen")] | ||
public string Screen { get; set; } | ||
|
||
[JsonProperty("data")] | ||
public object Data { get; set; } | ||
} | ||
|
||
public class FlowMessageBody | ||
{ | ||
[JsonProperty("text")] | ||
public string Text { get; set; } | ||
} | ||
|
||
public class FlowMessageFooter | ||
{ | ||
[JsonProperty("text")] | ||
public string Text { get; set; } | ||
} | ||
|
||
public class FlowMessageHeader | ||
{ | ||
[JsonProperty("type")] | ||
public string Type { get; set; } | ||
|
||
[JsonProperty("text")] | ||
public string Text { get; set; } | ||
} | ||
} |
Oops, something went wrong.