super-bot icon indicating copy to clipboard operation
super-bot copied to clipboard

Support multiple messages in the same request

Open gfaraj opened this issue 5 years ago • 6 comments

I would like to send multiple messages to the bot service in the same request.

gfaraj avatar Jan 21 '20 17:01 gfaraj

Yes, I'm waiting for it.

KstmSoft avatar Jan 21 '20 18:01 KstmSoft

Just curious, what would you like to use this for @KstmSoft ?

gfaraj avatar Jan 21 '20 20:01 gfaraj

@gfaraj, i want to use this for a Music Robot on Whatsapp. I would like when the user sends /music command send an message that notify him the music download and convert to mp3 process, and after that sends the audio. Hope you have an solution :+1:

KstmSoft avatar Jan 21 '20 21:01 KstmSoft

If I understand correctly, you're looking to have the bot respond periodically with the progress of the conversion progress, then send the audio when it is done.

If that's so, the periodic progress messages can be implemented in the current version of the bot by using the callbackUrl property available in the incoming messages.

Take a look how I did the reminders or trivia plugins.

As for sending the resulting audio data, the Whatsapp client currently only supports images. You might need to upload it somewhere and send the link instead.

gfaraj avatar Jan 22 '20 00:01 gfaraj

Yes, your solution works perfectly (in my case), I wrote an post call to callbackUrl sending the notification (same as reminders or trivia plugins do). I also implemented an simple function to do this more easier.

//target is the message parameter in bot.command

function notifyProcess(target, message){
    let body = {
        chat: { id: target.chat.id },
        text: `*[🕗 ${message}]*`
    };
    axios.post(target.callbackUrl, body)
    .then(async response => {
        if (response.status == 200) {
            console.log(`Received back: ${JSON.stringify(response.data)}`);
        }
    });
}

Thanks in advance, nice work!.

KstmSoft avatar Feb 17 '20 02:02 KstmSoft

Yeah I should really add a nicer way to send a callback message, thanks for the suggestion. Glad it worked out for you!

gfaraj avatar Feb 18 '20 21:02 gfaraj