Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

Question: How to trigger the convo.ask callback only if the user mentions the bot #436

Closed
ljfranklin opened this issue Oct 9, 2016 · 4 comments

Comments

@ljfranklin
Copy link

By default, the ask callback is triggered the next time the target user enters any message. I'd like to only trigger this callback if the target user's reply mentions the bot.

Desired behavior:

bot: @user how are you?
user: @bot great!
bot: @user you said "great!"

bot: @user how are you?
user: talking to someone else
# no response from bot
...
user: @bot doing fine now!
bot: @user you said "doing fine now!"

At a glance, I didn't see any properties in the response or convo that indicated whether the response included a mention or not. Thanks!

@lucasgreene
Copy link

lucasgreene commented Oct 14, 2016

@ljfranklin try convo.source_messsage. It should have an event property which will be direct_message, direct_mention, ect.

Edit: I misread your question. This won't help you. This would actually be decently hard I think because by default if you are in a conversation all messages are sent to the conversation once its started. I guess you could parse the @symbol ?

Edit2: Actually I think you won't be able to do this. By default the mentions are stripped out of the message and used to trigger the specific event, but the event won't be added to the response object because its already in a conversation. Check out SlackBot.js:

                // remove direct mention so the handler doesn't have to deal with it
                message.text = message.text.replace(direct_mention, '')
                .replace(/^\s+/, '').replace(/^\:\s+/, '').replace(/^\s+/, '');

@ghost
Copy link

ghost commented Nov 8, 2016

I think is not possible so the ask callback will be triggered always BUT... you can check the response in the callback function and if this response don't start with @bot use convo.silentRepeat(), you know?
Try this:

convo.ask('how are you', function(response, convo){
    if("CHECK THE response.text AS YOU WANT"){
        convo.next();
    }else{
        convo.silentRepeat()
        convo.next();
    }
});

@peterswimm
Copy link
Contributor

Closed as answered

@ljfranklin
Copy link
Author

@EloyRedondo thanks! Checking to see if the text contains bot.identity.name should do the trick.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants