How to make surveys: Three ways
# 📖tutorials
a
Hey bot builders! Do you want a bot that asks users questions and saves their answers? This tutorial is for you! You can follow along with the YouTube video here:

https://youtu.be/TDEjYBq2KIA

## Method 1: Capture Cards This one is pretty simple: use the default capture cards to ask questions and save user answers to variables. Pros: * Robust, simple, lots of options * Easy to add/remove questions * Simple fallbacks for invalid responses * Easy to add knowledge to a single question Cons: * Lots of nodes, can get complicated for long surveys * No AI-generated follow-ups or retry messages * Limited to capture card data types * Tedious to add knowledge to all questions
## Method 2: All-in-one AI Task With a comprehensive prompt, you can use a single AI task to guide the user through an entire survey! Here's the prompt I used in the video:
Copy code
md
Analyze the provided chat transcript and try to answer the following four questions:
1. What is the user's name?
2. What is the user's email address
3. Why does the user want an appointment?
4. When does the user prefers to be contacted (either morning, afternoon, or evening)

Understand what the user said and make a plan. Make sure you include all four pieces of information in your plan. Then execute the plan, paying attention to synonyms and common sense. When information is present, save it to the appropriate variable. Only change a variable's value if it is empty.


Always end by writing a relevant follow up using the next question. Ask questions one at a time. 

When all questions are answered, write a confirmation message including all information.
Pros: * Really cool! 😎 Cons: * Very fragile to changes like: * New or different survey questions * Updated GPT model * Out-of-scope questions or dynamic follow-ups * Multilingual responses * Hard to fine-tune * Difficult to extract niche info like SKUs or brand names
## Method 3: Code-guided AI Tasks This method uses code to give the AI task explicit instructions about what data to prompt for and what data to extract. It starts by defining JS classes for each data type:
Copy code
js
class UserName {
  name = 'name'
  value = 'Undefined'
  description = 'the users name'
  constructor(value) {
    this.value = value
  }
}
Then, pass the data class's description to an AI task to generate a prompt:
Copy code
md
You are a friendly AI that is asking users survey questions. Use the provided chat transcript for details (like their name) that can make the next question more personalized. 
Write a personalized, kind follow up question based on the direction. Pay attention, and make sure you follow the direction.
Finally, we use a second AI task to extract the data, using both the data class and the chat transcript as inputs:
Copy code
md
Extract the required information from the `userMessage`, paying special attention to the information emphasized in the input. 

When you find information, save it to the appropriate variable. If there is no information available, leave the variable empty. Finally, if you find additional relevant information you may extract it, too.
Pros: * More reliable than AI task alone * AI can answer out-of-scope questions and ask relevant follow-ups * Easy to add knowledge base, custom analytics * Less complicated to add new questions Cons: * Fragile to GPT model changes (but not as much as AI Task only) * Code-heavy and inscrutible to non-programmers * Can grow in complexity for larger surveys The bot is attached to this post. Happy Bot-building 🙌
w
The Code + AI Task is very interesting. Although I have a question on it. How would one handle say, a user gave a wrong time of appointment and the next message is to change the time. The bot takes this as the reason.
a
Ideally, since we defined the time as an enumerated class, the AI task shouldn't extract the time and shuld re-prompt the user. If we want to make sure this happens, we can also add some validation before we save the extracted value to make sure it is okay.
w
great! thanks all
q
@acceptable-kangaroo-64719 This is gold, man Idk I was using intents even. Going to use Ai extracting info + custom code combination. Thanks man.
l
Thanks for this! @acceptable-kangaroo-64719 is it possible to have different knowledge bases provided depending on the question that the bot is asking? Say we're testing user knowledge on topic1/topic2 and want to source different knowledge bases for each topic?
m
Hi, I have an issue with the last step of the method 3, extracting the data with an AI Task
I have that setup for the task and it doesn't capture the bookingRoomsAmount variable
it works fine with the previous 3 but with the last one it doesn't capture and loops asking the last question
I already added descriptions to the variables, it helped with the first one
r
Yeah I encountered this as well. Sometimes in the AI Task for followUpQuestion, i'm not sure why it keeps looping asking the same last question, and fails to regenerate what is the next question to ask. Seems pretty erratic and sometimes it happens, sometimes it doesn't. I get a sense it is that the output variable of the AI task fails to get set, thus the followup question remains at the previous one.
Did you manage to fix it @microscopic-lifeguard-11844 ?
Somehow there is a bit of hallucination and the AI Tasks tends to ask questions that are not within the scope of the "direction". I think it works better when I remove the chat context in the ai task. If needed, we can just pass in the users name into the ai task rather than pass in the whole chat transcript which seems to confuse gpt3.5 . E.g. I encountered a scenario where the followup question is supposed to be "Ask the user whether he wants to ship via air or ocean", but somehow the ai tasks transforms that direction into a followup question that states "What is the weight of your cargo."
m
No, I didn't solve it. I am playing with a mix of long prompts like the only AI solution and actions in assistant openai api.
j
i have this template
4 Views