👆 Translation from Russian to English is done by Telegram automatically, so enjoy the pre-school English
Idea
The initial idea behind it was to get user through Akinator-like process to figure out their disease and provide some recommendations (At some point we had a lawyer who had recommended us not to use terms like diagnosis or treatment plan for this project) they could follow before reaching for professional help. So, the bot is by no means a replacement for a doctor, but rather a tool to get a quick checkup before, but not instead of getting to a hospital.
Wrapping such a complex thing into a gamified questionnaire had hands:
- Contrary to Akinator, users don't know what they're looking for exactly.
- Most of the symptoms can be diseases by themselves, but also be a part of loads of other diseases. For a very bad example, headache can mean that user has a fever or a brain tumor. So we have to be precise with all the recommendations;
- At the same time, we can't go into too much detail, since it can be overwhelming for a user and they can miss something important.
Important side-note: I don't know shit about medicine and have to google almost every fancy-looking latin word I face, but on this project I was accompanied by two professional doctors handling all the medicine-related logic.
Flows
To implement branching and the overall question-to-question navigation, I implemented the questions using something I called Flows.
Considering this abstraction for questions:
const question = { id: 1337, text: 'Do you have a runny nose?', type: 'closed', // 'closed' | 'multiple-answers' | 'input' answers: [ { id: 1338, text: 'Yes', triggers: 4 }, { id: 1339, text: 'No', triggers: null } ]
...And this one for users' sessions:
const session = { userId: 'egorushque', //... currentQuestion: 1337, upcomingQuestions: [80085, 42, ...]
A flow is just a collection of questions. Each time a user answers a question, there's a check if their question triggers a flow. All the questions from the triggered flow are pushed to the upcomingQuestions
on user's session.
Telegram bots: both ugly and beautiful
This was my first experience with building a Telegram bot. I was quite surprised to find that Telegram API (and, therefore, all the frameworks) doesn't provide any somewhat complex abstractions.
For example, there's no such thing as a "form" or a "wizard", which would allow you to build a multi-step process with a single command. You're given with a set of basic building blocks (messages, buttons, etc.), and from there you're free to build any abstractions you need.
If you want to become an open-source superstar
You can try to build a framework for testing Telegram bots.
Thinking about it, I'm not sure what it should look like, but the fact is that there's still no such thing but a great demand for it.