Building the FAQs Activity

Overview

Now that we have a Sheet to support the FAQ activity, we can build that activity. The activity itself is not that complex it is comprised of just 8 steps. However, it may be a little daunting to some users and does require some basic work with the LUA scripting language. If that's not you, you will want a developer to help out.

Building the FAQ Activity

Add A New Activity

Click the 'New Activity' button to launch the Activity marketplace. Select the 'Blank activity' template and then add it to your Flow.

Rename the activity to 'FAQs'

Add the Steps

1. Add a Step and Name it FAQs Start

The purpose of this step is to determine if the user has already asked a question. If they have not, it will transition them to a step where they are prompted to ask their question. Otherwise, they will be routed to have their question processed, and, hopefully, answered!

This step will have no message for the user because it is used to transition the user to one of two other steps.

  • Toggle off the Wait for the user to execute actions
  • Add a Code action. The code you will use is below:
-- Check if userQuestion exists in the Context

if Context.check("userQuestion") then
    -- If the user has already asked a question then search for an answer
    Workflow.branch("SEARCH FOR AN ANSWER STEP ID")
else
    -- If the user has not already asked a question then get the user question
    Workflow.branch("GET USER QUESTION STEP ID")
end
FAQs Start Step side panel detailFAQs Start Step side panel detail

FAQs Start Step side panel detail

  • Save the FAQs Start step, we will come back and complete this code after we build a few more steps.

2. Add the "Get user question step"

Add another step to the canvas and name it "Get user question
In the side panel, enter a message that prompts the user for their question.

  • Next, add a Variable action.
  • In the left-hand dropdown, add a variable named userQuestion
  • In the right-hand dropdown, select {{userMessage}}
    This will store the user's question in a variable called {{userQuestion}}
  • Add a Go to action and in the dropdown type in Search for an answer. Because this step does not yet exist, use the Add step button to create the new step
  • Save the Get user question step
FAQ Activity - Get User Question Side Panel DetailFAQ Activity - Get User Question Side Panel Detail

FAQ Activity - Get User Question Side Panel Detail

3. Configure the "Search for an answer" step

Like FAQ Start, this step's job is to process information and transition the user to an appropriate step.
In this case, the step will use semantic search to compare the user's question against the list of FAQs and send them to one of three steps based on the results of the search.

  • Select the Search for an answer step on the canvas
  • Toggle off Wait for the user to execute actions
  • Add a code action
  • Enter the code below into the code editor
-- Enter sheet ID
sheetId = 'ENTER SHEET ID HERE'

-- Run FAQ search
result = FAQ.searchQuestion(Context.get('userQuestion'), sheetId)

-- If a single answer is found
if result.singleMatch then
    Context.set("FAQsMatchQuestion", result.matchQuestion)
    Context.set("FAQsMatchAnswer", result.matchAnswer)
    Workflow.branch("FOUND ANSWER STEP ID")
end

-- If multiple answers are found
if result.multipleMatch then 
    Context.set("FAQsQuestions", result.faqs)
    Workflow.branch("FOUND MULTIPLE ANSWERS STEP ID")
end

-- If no answers are found
if result.noMatch then 
    Workflow.branch("FOUND NO ANSWERS STEP ID") 
end
  • Save the step
  • Go to the sheets tab and copy your sheet ID
FAQ Activity - Sheet IDFAQ Activity - Sheet ID

FAQ Activity - Sheet ID

  • Go back to the Flow canvas and the Search for an answer step
  • update the sheetId variable value from "ENTER YOUR SHEET ID HERE" to the ID you copied from your sheet
    Example
    sheetId='61e87cc34b7680865bf32afc'
FAQs Activity - Search for Answer Code DetailFAQs Activity - Search for Answer Code Detail

FAQs Activity - Search for Answer Code Detail

  • Save the "Search for an answer" step. We will come back and configure the code after we create a few more steps.

4. Finish Configuring the "FAQ Start" Step

Now that we have created the Get user question step and the Search for an answer step, we can finish configuring the FAQ Start step. What we are configuring is the branching or transitions based on whether or not the Flow already has a question saved in userQuestion.

Every step in a Flow has a unique, numerical ID and this is the information we need for the Workflow.branch() functions.

FAQs Activity - Finding Step IDsFAQs Activity - Finding Step IDs

FAQs Activity - Finding Step IDs

  • Look at your Get user question step. There will be a numerical ID on the step. Note this ID. Do the same for the Search for an answer step. In this example, the relevant step IDs are 21 and 22

  • Select the FAQ Start step and expand the code editor for the Code action we created earlier.

-- Check if userQuestion exists in the Context

if Context.check("userQuestion") then
    -- If the user has already asked a question then search for an answer
    Workflow.branch(22)
else
    -- If the user has not already asked a question then get the user question
    Workflow.branch(21)
end
  • On line 5, update Workflow.branch() with the step ID for Search for an answer. In the example, that Step ID is 22
  • On line 8, update Workflow.branch() with the step ID for Get user question. In the example, that Step ID is 21
  • Save the step
FAQs Activity - Search for Answers Side PanelFAQs Activity - Search for Answers Side Panel

FAQs Activity - Search for Answers Side Panel

5. Create the "Found multiple answers" Step

  • Add a new step and name it "Found multiple answers"
  • Add the following text to a message
We found the following questions that might help you 👇

{{#each FAQsQuestions}}
    {{index}}) {{title}}
{{/each}}

Please, type the number of the question you want answered.

Feel free to update the copy to match your own, unique voice.
The handlebars code will create a numbered list of the answers found for the user to select from.

  • Add a Code action to evaluate the user response and transition the user
-- Get user message
message = Context.get("userMessage")
--Debug.print("message" .. message)

-- Get only the number from the user message
-- "I want option 2" returns "2"
selection = String.onlyNumbers(message)
--Debug.print("selection" .. selection)
-- Get questions saved in previous step
questions = Context.get("FAQsQuestions")
--Debug.print(questions)

-- Ensure the Context variable exists
if Context.check("FAQsQuestions") then
    -- Convert JSON to Lua Table (Object)
    questions = JSON.decode(questions)
    --Debug.print(questions)
    
    -- Loop through the questions searching if the number entered by user
    -- matches any of the questions
    for key, question in pairs(questions) do
        -- If question index matches number entered by user
        if question.index == selection then
            Context.set("FAQsMatchId", question.id)
            Context.set("FAQsMatchQuestion", question.title)
            Context.set("FAQsMatchAnswer", question.content)
            --Debug.print("going to answer")
            Workflow.branch("FOUND ANSWER STEP ID") 
        end
    end
end
  • Save the step, we will finish configuring it in a later step
FAQs Activity - Found Multiple Answers MessagesFAQs Activity - Found Multiple Answers Messages

FAQs Activity - Found Multiple Answers Messages

FAQs Activity - Found Multiple Answers ActionsFAQs Activity - Found Multiple Answers Actions

FAQs Activity - Found Multiple Answers Actions

6. Add the "Found answer" Step

  • Add a new Step and name it "Found answer"
  • Enter the following text in the message field
Q: {{FAQsMatchQuestion}}

A: {{FAQsMatchAnswer}}

The copy above uses handlebar notation to write out the relevant question and answer.

  • Add "Buttons" to the message to determine if the user's question was answered or not

  • Save the step now, we will finish configuring it in a later step

FAQs Activity - Found Answer MessagesFAQs Activity - Found Answer Messages

FAQs Activity - Found Answer Messages

FAQs Activity - Found Answer ActionsFAQs Activity - Found Answer Actions

FAQs Activity - Found Answer Actions

7. Create the "Found no answers" Step

  • Create a new step and name it "Found no answers"
  • In the Message field, write a message that lets the user know that a suitable answer was not found and they can either go back to the menu or ask a new question.

We didn't find an answer to your question. Please, try again with a different question or type 'exit' to go back to the menu

  • Add a Code action to delete the previous question from the user's context
Context.delete("userQuestion")
  • Add a Conditional action to determine if the user wants to exit back to the menu
  • Use the Contains keywords condition and use a value of exit
  • If the user did type exit then transition them (via the go-to) back to the menu
  • Enable the fallback (if no condition was met) and add a Save variable action to save the new user question
  • Set {{userMessage}} to {{userMessage}} to save the current message from the user as the new question
  • Transition the user back to the Search for an answer step
  • Save the Found no answer step
FAQs Activity - Found No Answer MessageFAQs Activity - Found No Answer Message

FAQs Activity - Found No Answer Message

FAQs Activity - No Answer Found ActionsFAQs Activity - No Answer Found Actions

FAQs Activity - No Answer Found Actions

8. Finish Configuring the "Found multiple answers" Step

  • Get the step ID for the "Found answer" step
  • Select the Found multiple answers step
  • Update the code action with the step ID for the "Found answer" step - 31 in the case of our example Flow
-- Get user message
message = Context.get("userMessage")
--Debug.print("message" .. message)

-- Get only the number from the user message
-- "I want option 2" returns "2"
selection = String.onlyNumbers(message)
--Debug.print("selection" .. selection)
-- Get questions saved in previous step
questions = Context.get("FAQsQuestions")
--Debug.print(questions)

-- Ensure the Context variable exists
if Context.check("FAQsQuestions") then
    -- Convert JSON to Lua Table (Object)
    questions = JSON.decode(questions)
    --Debug.print(questions)
    
    -- Loop through the questions searching if the number entered by user
    -- matches any of the questions
    for key, question in pairs(questions) do
        -- If question index matches number entered by user
        if question.index == selection then
            Context.set("FAQsMatchId", question.id)
            Context.set("FAQsMatchQuestion", question.title)
            Context.set("FAQsMatchAnswer", question.content)
            --Debug.print("going to answer")
            Workflow.branch(24) 
        end
    end
end
  • Save the step

9. Create Steps to Capture FAQs Feedback

  • Select the Found answer step
  • Add a Condition action
  • Use Contains keywords to evaluate if the user selected the Yes button and transition them to a new step called Successfully answered
  • Add another Condition action
  • Use Contains keywords to evaluate if the user selected the No button and transition them to a new step called Unsuccessfully answered
  • Save the step
  • Arrange the new steps on your canvas so they are visible and easily selectable

10. Configure the "Successfully answered" Step

  • Confirm for the user that the Flow received their response by responding with a positive message
    Glad we could help you!

  • Add a button message that allows the user to go back to the menu or ask another question

  • Add a code action to delete the current userQuestion variable

Context.delete("userQuestion")
  • Add a Contains keywords Condition to transition the user to the menu if they selected the menu button
  • Enable the fallback and use Save Variable to store the current {{{userMessage}} in {{userQuestion}} and transition the user back to Search for an answer
  • Save the step
FAQs Activity - Question Successfully Answered MessagesFAQs Activity - Question Successfully Answered Messages

FAQs Activity - Question Successfully Answered Messages

FAQs Activity - Question Successfully Answered ActionsFAQs Activity - Question Successfully Answered Actions

FAQs Activity - Question Successfully Answered Actions

11. Configure the "Unsuccessfully answered" Step

  • Confirm for the user that the Flow received their response by responding with a positive message
    Sorry we could not find an answer to your question. 😔
  • Add a button message that allows the user to go back to the menu or ask another question
  • Add a code action to delete the current userQuestion variable
  • Add a Contains keywords Condition to transition the user to the menu if they selected the menu button
  • Enable the fallback and use Save Variable to store the current {{{userMessage}} in {{userQuestion}} and transition the user back to Search for an answer
  • Save the step

12. Add a Fallback Step for the Found multiple answers step

Sometimes, a user will do something unanticipated. In this case, it is possible a user will send a message that does not match one of the available answers in Found multiple answers in this case, we want to create a fallback that re-routes the user back to the Found multiple answers step.

  • Select the Found multiple answers step
  • Add a Contains keywords Condition
  • Grab the Condition handle and drag it above the Code action (remember, actions are processed from top to bottom and we want this condition to be evaluated before the Code action)
  • Set the contains keyword value to 'none' and transition the user to the Unsuccessfully answered step
  • Enable the Fallback action
  • Create a new step called "FAQs no valid option fallback" via the Go To inside the Fallback action
  • Save the step

13. Configure the "FAQs no valid option fallback" Step

  • Select the FAQs no valid option fallback step
  • Enter a message letting the user that their message didn't match any of the listed answers
  • Switch the Wait for the user to execute actions toggle to off
  • Add a Go To action that transitions the user back to the Found multiple answers step
  • Save the step
    ###14. Don't forget to connect your new FAQs activity to the rest of the flow via its menu and/or a global action
    ###15. Publish your workflow and test the FAQs activity
FAQs Activity - No Valid Option Provided Step Side PanelFAQs Activity - No Valid Option Provided Step Side Panel

FAQs Activity - No Valid Option Provided Step Side Panel

Considerations


Did this page help you?