Collecting invoices and receipts for travel-related expenses is a common process in most of the businesses. Our client wanted to make this process easier and use the latest technologies to help their employees. The requirement was to enable employees to provide these documents about their expenses in Facebook Messenger by communicating with a bot that collects every required information helping the finance team to process them. The functionality was built to extend the existing application which handles and reconciles the accounts payable items.
In this post*, we will go through how to set up a Messenger channel and process a case that handles invoices/receipts.
*The below tutorial was made based on the “Saltech version” of the solution that has been modified to remove all client-specific information.
To begin, you are required to have a Facebook channel component (download here).
If the component is installed, you will be able to create a Messenger channel at Channels and interfaces screen.
It is required to have a Facebook page and a Facebook developer account for the configuration.
Once you have it, log in to the Facebook developer site, click on create a new application and give it a name.
On the left, click on the plus marker next to the products and select Messenger.
For the Messenger component, you are required to have an access token of the Facebook application and the Facebook page ID.
To get the access token, add our page to the Messenger product.
The next step is to set up the new channel in Pega, give it a name and a description. On the ‘Connection’ tab fill out the page ID, template operator ID and access token with the newly gathered pieces of information.
After saving the configuration in Pega, a webhook has to be set with a callback URL on the developer portal of Facebook. Keep in mind that this URL has to be HTTPS. Something like: “https://yourdomain.com/prweb/PRHTTPService/channel/srv/fb”.
The channel rule in Pega has to be set up with the authentication URL, which will be “https://yourdomain.com/prweb/PRHTTPService/channel/srv/fblogin”.
(For “verify token”, you can type in anything.)
For our purposes 3 different types of webhooks have to be selected:
At this point, our bot is up and running. You are able to send a message to the Facebook page and the bot will respond.
It is needed to add developers/testers to tester/dev group on the Facebook developer site or the bot will not answer them.
To be able to initiate a case from Messenger, a case type has to be listed in the channel configuration with the start command.
In our case, we will create a Process Debtor Item case type with the command “ProcessDebtoritem”. We use this case type to gather the required data for the invoices and receipts (debtor items) and save them in our system while creating an asana task for the colleague at finance.
After the command is created, a zero stage has to be created in the case type (or select Facebook on the first stage creating a parallel process for Messenger), where the user will be asked to answer questions and/or provide attachments before the case moves to the next stage.
The flow to gather all the necessary information has to be created next. It is built with a list of questions. Check the “Facebook” checkbox on the Channel specific conversations.
It will generate the “Facebook-Messenger” question step. This step contains a question sub-flow with all the questions the bot will ask the user. After all these questions are answered, we change to the next stage.
Click on the “Facebook-Messenger” step then “Configure conversation” to add questions to fill the properties from the answer.
It’s important to add a final question to the flow which is configured with a question rule in “Show display text only answer” mode. If you miss this, after all the questions are answered, the bot will crash because it will try to get to the next step, which is not chat-based.