var rx=/(.+)/;
var emptyFn=function(){};
bot.sendMessage(this.userId, 'Where do you want to know the weather forecast?')
.then(() => {
this.onText(rx, msg => {
console.log(msg);
this.onText(rx, emptyFn);
});
});
describe('#onText', function onTextSuite() {
it('should call `onText` callback on match', function test(done) {
const regexp = /\/onText (.+)/;
botWebHook.onText(regexp, (msg, match) => {
assert.equal(match[1], 'ECHO ALOHA');
assert.ok(botWebHook.removeTextListener(regexp));
return done();
});
utils.sendWebHookMessage(webHookPort2, TOKEN, {
message: { text: '/onText ECHO ALOHA' },
});
});
it('should reset the global regex state with each message', function test(done) {
const regexp = /\/onText (.+)/g;
botWebHook.onText(regexp, () => {
assert.equal(regexp.lastIndex, 0);
assert.ok(botWebHook.removeTextListener(regexp));
return done();
});
utils.sendWebHookMessage(webHookPort2, TOKEN, {
message: { text: '/onText ECHO ALOHA' },
});
});
});