Giter Site home page Giter Site logo

Comments (8)

LAMike310 avatar LAMike310 commented on July 30, 2024

I'm trying to write a program that listens for multiple, but similar keywords. I have a separate function that takes in one of these keywords, and spits back some data to Slack.

I could make a separate controller function for each keyword to send that data to a function I made, but it would save me a lot of typing if I could put multiple keywords in a controller function, and then grabbing what the user says inside one function. Does that make sense? Sorry if it sounded like I'm rambling.

Thanks,

Mike

from botkit.

LAMike310 avatar LAMike310 commented on July 30, 2024
controller.hears(['Apple', 'Orange'],['direct_message,direct_mention,mention'],function(bot,message) {
    console.log("You said " + message.text)
});

from botkit.

benbrown avatar benbrown commented on July 30, 2024

You got it.

You can also use normal Javascript string parsing tools like message.text.match() which can extract a keyword from a pattern.

from botkit.

guillaumepotier avatar guillaumepotier commented on July 30, 2024

Hi there,

I think with my PR #39 you'll be able to directly see in message.match what matched in message.text and triggered this listener.

That's what I'm expecting to do with RegExp patterns.

On antoher unrelated note, I'll have to test but it seems that controller.hears(['Apple', 'Orange'], ... is slower than controller.hears(['(Apple|Orange)'], ... that would make less for loops in the lookup code.

Best

from botkit.

guillaumepotier avatar guillaumepotier commented on July 30, 2024

Good news, #39 have been merged, you could now really use message.match object (generally message.match[1] when only one capturing group) inside the response to see what triggered it :)

Best

from botkit.

benbrown avatar benbrown commented on July 30, 2024

Pretty cool!
We should consider cleaning up that object to make it easier to use.

from botkit.

LAMike310 avatar LAMike310 commented on July 30, 2024

Thanks for the tips @benbrown and @guillaumepotier!

from botkit.

RafaelCosman avatar RafaelCosman commented on July 30, 2024

@LAMike310 let us know if you have any other questions about this.

Should we close the issue?

from botkit.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.