gfaraj / super-bot

A simple but extensible bot written in Node (with Whatsapp, Slack, and Discord interfaces)
MIT License
23 stars 15 forks source link

Support multiple messages in the same request #23

Open gfaraj opened 4 years ago

gfaraj commented 4 years ago

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

KstmSoft commented 4 years ago

Yes, I'm waiting for it.

gfaraj commented 4 years ago

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

KstmSoft commented 4 years ago

@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:

gfaraj commented 4 years ago

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.

KstmSoft commented 4 years ago

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!.

gfaraj commented 4 years ago

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