Creating a simple bot

#1

Hello Botmakers!

Would be greatful if you help a newbie - me :slight_smile:
For most of you this bot will be simple, I believe.

I would like to create a bot that every Thursday at 1 pm will ask bot users a question.
Each week, same time, same shortcuts/answers/buttons.
These shortcuts are numbers(from 0 to 9) that needed to be summed up(number from user0 + number from user1 + number from user2…n) after user choses one of them.
This sum should be saved and update every time any new user gives or changes his answer.
Sum should be available on demand through command “request sum”.
For example, I choose “2”, Denis choosed “3”. I tap on “request sum” and receive 5 as answer.

I’ve made:
-welcome flow
-wait block (wait until Thursday 1 PM)
-ask question with 9 shortcuts (0 to 9)
-ask question with 9 shortcuts(to give ability user to change previously chose number) + shortcut to request sum
current to this moment

So I have few questions:
-How to organize summing?
-How to bind execution of sum functino to “request sum” shortcut(button) from second question block?
-How to “reboot”(or clear sum and numbers, to be more accurate) bot every Saturday? I don’t need sum or numbers to be saved or stored after every Saturday.
-Where am I? That was a joke, sorry :slight_smile:

(John Jackson) #2

Happy to give you some pointers! :grinning:

There are a few ways to go about this.

For actually asking the questions you could a ‘Broadcast > Webhook’ trigger, and then ask a question, then finally save the answer to an attribute (instead of response path when saving the attribute, save it ‘globally’. So edit the response path field, and use any word you want in there, so maybe ‘all_users’). Give the attribute a name, and use the notation ‘+(value)’ to add a number to the total.

It should look kind of like this:

So you now have a broadcast trigger (webhook URL) that every time you hit it, every user of your bot is asked a question, and their answer is summed up in an attribute.

Unfortunately we have no way (yet) to schedule something every Thursday at 1pm. Instead, you should use another service (maybe Zapier or a web cron job service?) to hit the webhook URL every Thursday at 1pm.

Finally you need a flow to get the sum, and another to maybe clear the sum. They should be straightforward for you, getting and setting attributes.

Hopefully this gets you on the right road! Good luck with it.

1 Like
#3

Hey, John!

Thanks. You’ve helped a lot!
Everything works just fine:
broadcasting - asking question and parsing answers - setting attribute and summing all users - and getting attribute(it’s Telegram bot btw).
Though there are some question left :slight_smile:

How to create “/…” commands?
What I mean:
I want to give every user an ability to check sum attribute at any moment. This command should not expire.
And can be put into message from bot(blue colored and tapable, you know) and/or inside [ / ] button menu (the button that is located in Telegram’s text field) - so user can see it and use it whenever he wants.

(John Jackson) #4

You can use a bot ‘New Message’ trigger with a word beginning with /. So something like /total. Simply listen for the command as a word/phrase.

To add it as a known command in Telegram’s menu, you can use the /setcommands option in @BotFather.

1 Like
#5

“That’s easy!” was my thought at first.
This means I need to start a separate flow with ‘New Message’ that will listen to word ‘/total’.
But the following problem occurs: this separate flow(connected and listening to my bot, of course) doesn’t seem “to know” where to look for ‘attribute_sum’ from the main Broadcast flow.
What did I miss here?

UPD: Should ve used ‘Get an Attribute’ . So obvious!

(Brain) #6

Webcron is useful to webmasters. I use a Webcron service called easycron.com to trigger the cron php script to run.