Skip to content

Instantly share code, notes, and snippets.

@FredrikOseberg
Last active March 12, 2021 06:44
Show Gist options
  • Save FredrikOseberg/161bbcc7220ded5de7a1fce834d7fe99 to your computer and use it in GitHub Desktop.
Save FredrikOseberg/161bbcc7220ded5de7a1fce834d7fe99 to your computer and use it in GitHub Desktop.
class MessageParser {
constructor(actionProvider, state) {
this.actionProvider = actionProvider;
// State represents the chatbot state and is passed
// in at initalization. You can use it to read chatbot state
// inside the messageParser
this.state = state
}
parse = (message) => {
const lowerCase = message.toLowerCase();
if (
lowerCase.includes("messageparser") ||
lowerCase.includes("parse") ||
lowerCase.includes("parser") ||
lowerCase.includes("message parser")
) {
return this.actionProvider.handleMessageParser();
}
return this.actionProvider.handleDefault();
};
}
export default MessageParser;
@tarun080698
Copy link

...
  parse = (message) => {
     let toCheck = ['messageparser', 'parse', 'parser', 'message parser'];
    const lowerCase = message.toLowerCase();

    if (toCheck.some((item) => lowerCase.includes(item))){
      return this.actionProvider.handleMessageParser();
    }
    return this.actionProvider.handleDefault();
  };
}

...

you can make these changes to make it more simpler

@hedaukartik
Copy link

if we have one string inputs from the user in the text field, but it can be for search flight or for search airport, how will we distinguish and parse and call the API according? Also, can we read the input text field and previously selected options together and check?

Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment