- CxPerium WhatsApp Flows Documentation
- 1. What is WhatsApp Flows?
- 2. Advantages of WhatsApp Flows
- 3. How to Use WhatsApp Flows with CxPerium?
- 3.1 Sending a Flow Message in CxPerium
- 3.2 Capturing Flow Data
- 3.3 Example Flow Usage
- Dialog that Captures Form Data
- 4. Using Endpoints in Flows
- 4.1 Handling data_exchange Action
- 5. Generating RSA Keys for WhatsApp Flows
- Adding the Private Key File
- 6. Conclusion
CxPerium WhatsApp Flows Documentation
This document provides a detailed guide on how to use the WhatsApp Flows feature in CxPerium SDK to create custom chatbots on WhatsApp. We will go step by step to explain what Flows are and examine practical examples.
1. What is WhatsApp Flows?
WhatsApp Flows is a business messaging feature that allows businesses to create structured interactions. It goes beyond traditional chat-based dialogues by enabling users to share information through a form-like interface without leaving WhatsApp. This provides:
- A more seamless user experience.
- More organized and structured data collection.
- Faster and more efficient data acquisition for businesses.
For more information, visit the [[Official WhatsApp Flows Documentation](https://developers.facebook.com/docs/whatsapp/flows/)].
2. Advantages of WhatsApp Flows
- Structured Interactions: Businesses can create a more planned and organized communication model with their customers.
- Enhanced Forms: Flows enable data collection beyond simple text-based messaging.
- Stay Within WhatsApp: Users can share information without being redirected to another app or website.
- Faster and More Effective Interaction: Structured data collection processes save time for both users and businesses.
- Improved User Experience: A more intuitive and easy-to-understand data collection structure.
3. How to Use WhatsApp Flows with CxPerium?
3.1 Sending a Flow Message in CxPerium
In CxPerium, the this.Messages.SendFlowMessage
method is used to send a WhatsApp Flows message. This method has multiple overloads, each designed to cater to different needs.
Below are the different usages of this method:
1. Usage
SendFlowMessage(
string message,
string headerText,
string footerText,
string buttonText,
Type catchedDialog,
string flowIdOrName,
string screen
)
2. Usage
SendFlowMessage(
string message,
Uri url,
string footerText,
string buttonText,
Type catchedDialog,
string flowIdOrName,
string screen
)
3. Usage
SendFlowMessage(
string message,
Uri url,
string footerText,
string buttonText,
Type catchedDialog,
string flowIdOrName,
string screen,
JObject data
)
4. Usage
SendFlowMessage(
string message,
string headerText,
string footerText,
string buttonText,
Type catchedDialog,
string flowId,
string screen,
JObject data
)
3.2 Capturing Flow Data
To capture data from a Flow, your dialog must:
- Derive from
BaseWhatsAppDialog
. - Implement the
IFlowReceiveMessage
interface.
using Newtonsoft.Json.Linq;
using QSoft.CxPerium.Dialogs.WhatsApp;
namespace QSoft.CxPerium.Assistant.Dialogs
{
public class UserFormHandlerDialog : BaseWhatsAppDialog, IFlowReceiveMessage
{
public void ReceiveFlowMessage()
{
JObject formValue = this.Activity.Form.ResponseJson;
// Process form data here.
}
}
}
3.3 Example Flow Usage
Dialog that Opens the Form
using QSoft.CxPerium.Dialogs.WhatsApp;
using System;
namespace QSoft.CxPerium.Assistant.Dialogs
{
public class MainDialog : WelcomeDialog
{
public override void RunDialog()
{
this.Messages.SendFlowMessage(
“Fill out the form below for your support request.”,
“Form”,
“Your request will be answered as soon as possible.”,
“Open Form”,
typeof(UserFormHandlerDialog),
“customer_support”,
“DETAILS”
);
}
}
}
Dialog that Captures Form Data
using Newtonsoft.Json.Linq;
using QSoft.CxPerium.Dialogs.WhatsApp;
namespace QSoft.CxPerium.Assistant.Dialogs
{
public class UserFormHandlerDialog : BaseWhatsAppDialog, IFlowReceiveMessage
{
public void ReceiveFlowMessage()
{
JObject formValue = this.Activity.Form.ResponseJson;
Messages.SendMessage($”The order form entered is {formValue[“screen_0_Order_number_1″]} types”);
}
}
}
4. Using Endpoints in Flows
To make a Flow interact dynamically with an endpoint, configure your bot’s URL to:
https://yourboturl/api/CxPerium/flows
This endpoint manages Flow screen transitions and form dynamics.
4.1 Handling data_exchange Action
To handle data_exchange
actions in a Flow, implement the IFlowDataExchange
interface:
public class UserFormHandlerDialog : BaseWhatsAppDialog, IFlowDataExchange
{
public FlowResponse DataExchange(FlowRequest request)
{
var exchangeData = request.Data;
var response = new FlowResponse();
response.Screen = “another_screen”;
response.Action = “navigate”;
return response;
}
}
5. Generating RSA Keys for WhatsApp Flows
To securely exchange data with WhatsApp Flows, a 2048-bit RSA key is required. Refer to the [[WhatsApp Business Encryption Guide](https://developers.facebook.com/docs/whatsapp/cloud-api/reference/whatsapp-business-encryption)] for details.
Adding the Private Key File
- File Name:
private.pem
- Set Build Action to Embedded resource.
6. Conclusion
CxPerium enables businesses to leverage WhatsApp Flows for structured and efficient customer interactions. This document provides an in-depth guide to implementing Flows, capturing data, and using dynamic endpoints securely.