Replies: 1 comment
-
Very nice, this can be used for many things. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Lets say you have 3 questions,
age range
,gender
andcountry
:You can encode the button ID with the quiz state relating to that answer. So let's say we start the quiz by asking the age range with 3 standard quick reply buttons. The buttons will be as follows:
eyJhZ2VfcmFuZ2UiOiIwLTE1In0=
eyJhZ2VfcmFuZ2UiOiIxNi0yMiJ9
eyJhZ2VfcmFuZ2UiOiIyMy00MCJ9
As you can see, the base64 encoded button ID is the end state after answering the question with the relevant answer.
The code will be as follows:
Let's assume the user selected the first option
"0-15"
, the next question isgender
with three more options.eyJhZ2VfcmFuZ2UiOiIwLTE1IiwgImdlbmRlciI6ICJtYWxlIn0=
eyJhZ2VfcmFuZ2UiOiIwLTE1IiwgImdlbmRlciI6ICJmZW1hbGUifQ==
eyJhZ2VfcmFuZ2UiOiIwLTE1IiwgImdlbmRlciI6ICJvdGhlciJ9
The base64 buttons IDs are naturally longer because the quizstate object has more data. Assuming the user selected 1, the button ID of the response will be
eyJhZ2VfcmFuZ2UiOiIwLTE1IiwgImdlbmRlciI6ICJtYWxlIn0=
.Now, onto the last question,
country
. There are 195 countries in the world. Let's assume our users are in one of 20 countries. You cannot usesendButtons
with 20 options. Luckily, you can usesendListMessage
instead.Now we can introduce some quality of life improvements to dynamically generate the required list message.
And voila, when you get the response for this last list message, you can determine that the quiz has ended (because all properties are answered) and you've done it without integrating a database to save conversation/quiz state and without integrating dialogflow (which is not free at scale nor stateful beyond 5 minutes).
What's next?
Ideally, there should be an inbuilt quiz management which dynamically does the background work for you and uses a message collector type system to emit finalized quizzes for you.
[TBC]
Ref (from discord discussion):
#1794 (comment)
Beta Was this translation helpful? Give feedback.
All reactions