In this section, we will detail the steps to create a dialog for a chatbot using the QSoft.CxPerium .NET SDK. Dialogs manage the flow of interactions between a user and the bot and form the foundation of the user experience.
1. What is a Dialog?
A dialog is a logical structure that defines how a chatbot responds to user queries or handles a workflow. In the QSoft.CxPerium SDK, dialogs are programmed within a defined logic framework to achieve the desired outcomes.
2. Core Dialog Components
The essential components used when creating a dialog are:
- Contact: Represents the user sending the message, corresponding to an entry in the CxPerium Contacts list.
- Activity: An object that defines the type and value of the received message. For example, it holds information on whether the user pressed a button or sent a location.
- Conversation: An object that stores temporary data throughout the conversation.
3. Example Dialog: “Who Are You?”
In this section, we will create a dialog where, when a user sends the message “who are you,” the bot responds with “I am a special assistant.”
3.1 Creating the Dialog Class
- Dialogs Folder: Create a folder named
Dialogs
in your project. - New Class: Within this folder, create a new C# class file (.cs) and name it
WhoAreYouDialog
.
3.2 Class Structure and Requirements
To define a class as a dialog in the QSoft.CxPerium SDK, follow these steps:
- Inherit from the
BaseWhatsAppDialog
class. - Implement the
IWhatsAppDialog
interface. - Implement the
RunDialog
method as required by theIWhatsAppDialog
interface.
The RunDialog
method is triggered when the dialog matches the user’s input. Inside this method, you can use the Messages
object from the BaseWhatsAppDialog
class to send messages to the user.
3.3 Example Code
The following example shows a dialog that responds with “I am a special assistant”:
using QSoft.CxPerium.Dialogs.WhatsApp; namespace QSoft.CxPerium.Assistant.Dialogs { public class WhoAreYouDialog : BaseWhatsAppDialog, IWhatsAppDialog { public void RunDialog() { this.Messages.SendMessage("I am a special assistant"); } } }
4. Mapping the Dialog in CxPerium
To ensure your dialog matches the user’s “who are you” input, follow these steps:
- Log in to CXPerium: Access the CXPerium platform.
- Go to Assistant > Dialog Page: Navigate to the “Assistant” menu and open the “Dialog” page.
- Create a New Dialog: Click on the “New Dialog” button.
- Enter the Details: Fill in the form with the following information:
- Dialog Name: Use the full namespace of the
WhoAreYouDialog
class, i.e.,QSoft.CxPerium.Assistant.Dialogs.WhoAreYouDialog
- Report Name: Enter a descriptive name for reporting purposes.
- Language Selection: Choose the language in which the dialog will be recognized.
- Regex Value: Define the message pattern that will trigger this dialog. In this case, enter “who are you”.
- Dialog Name: Use the full namespace of the
- Save: Click the “Save” button to complete the setup.
5. Summary of Steps
- Create a Class: Define a class named
WhoAreYouDialog
. - Inherit from BaseWhatsAppDialog: Extend the
BaseWhatsAppDialog
class. - Implement IWhatsAppDialog: Implement the
IWhatsAppDialog
interface. - Define the RunDialog Method: Write the response logic inside the
RunDialog
method. - Use the Messages Object: Send a message using the
Messages.SendMessage
method. - Map in CXPerium: Register and configure your dialog in the CXPerium platform.
Using this simple dialog structure, you can expand your chatbot’s capabilities and create more complex workflows.