yagop / telegram-bot

UNMAINTAINED - A Telegram Bot based on plugins
GNU General Public License v2.0
848 stars 502 forks source link

Unable to delivered sorted messages #245

Open jmontane opened 9 years ago

jmontane commented 9 years ago

Hi,

I'm working in a own plugin. This plugin sends severals messages: 3 text messages and 1 document in following sorting.

send_large_msg(receiver, Message1) send_large_msg(receiver, Message2) send_document(receiver, FilePath1, ok_cb, false) send_large_msg(receiver, Message3)

But user receives messages in following sorting

send_large_msg(receiver, Message1) send_large_msg(receiver, Message2) send_large_msg(receiver, Message3) send_document(receiver, FilePaht1, ok_cb, false)

Sometimes text messages are received unsorted, for instance,

send_large_msg(receiver, Message2) send_large_msg(receiver, Message1) send_large_msg(receiver, Message3) send_document(receiver, FilePaht1, ok_cb, false)

Is there any way to force messages to be delivered in desired sorting? Thanks in advance.

yagop commented 9 years ago

Use callbacks. Something like:

send_document(receiver, FilePath1, function (params) local receiver = params[1] local text = params[2] send_msg(receiver, text, ok_cb, false) end, {receiver, text})

rockneurotiko commented 9 years ago

In #246 I've added a function to utils.lua to send messages in order in an easy way, when @yagop accept it (if he does, maybe my way is wrong xD) you will can send easily messages in order (including send files/images/...)

jmontane commented 9 years ago

Thanks for quick replies,

I'm not a programmer guy, I was unable to achieve sort messages using callback functions. I think send_order_msg function can be a good improvement.

rockneurotiko commented 9 years ago

Your welcome! send_order_msg has been merged in a07b795, update your repo (./launch.sh update) and you will can use it :smile: To know how to use, see this: https://github.com/yagop/telegram-bot/pull/246#issue-86152981