aichaos / rivescript-js

A RiveScript interpreter for JavaScript. RiveScript is a scripting language for chatterbots.
https://www.rivescript.com/
MIT License
377 stars 144 forks source link

Cannot capture emails with star #244

Open webfrank opened 7 years ago

webfrank commented 7 years ago

Is not possible to capture emails (containing @ and dots or dash) because messages are parsed by the function stripNasties which strips everything but a-zA-Z and space.

josephrexme commented 7 years ago

@webfrank You'd have to enable utf8 when instantiating Rivescript i.e new Rivescript({ utf8: true })

kirsle commented 7 years ago

Even so, the periods will be stripped out because of the unicodePunctuation. There's a related bug and some discussion about it at https://github.com/aichaos/rivescript-go/issues/31.

If somebody wants to come up with the regexp described there and submit a pull request to either project, it can get fixed sooner and you'll help me with all the other RiveScript versions to get this change implemented everywhere.

As a hacky workaround, you could store the user's original message via rs.setUservar before calling rs.reply[Async], and then deal with getting their email address from inside an object macro. You could recall the variable like rs.getUservar(rs.currentUser(), "rawMessage") from inside an object macro, and then parse the email out yourself.

josephrexme commented 7 years ago

No they wouldn't be if you do this.

const bot = new Rivescript({ utf8: true })
bot.unicodePunctuation = new RegExp(/[~]/)

That's how I get around it. Basically tells it to only strip out ~ character which I never find myself needing