can't set afterProcessingUserMessageTimeout on each bot.usersInput.
yahsan2 opened this issue · comments
I usually would like to set depends on the callback function of hears.
botkit-mock/lib/BotmockWorker.js
Line 106 in 40179b2
hey @yahsan2
could you show me example of usage
I use mocha and chai.
test_something.js
beforeEach(async()=>{
this.controller = Botmock({})
this.bot = this.controller.spawn({
type: 'slack',
afterProcessingUserMessageTimeout: 1000,
})
})
// TEST 1
it('should return unsynchronized something 1', async() => {
const message = await this.bot.usersInput([
{
user: 'someUserId',
channel: 'someChannel',
messages: [
{
text: `something 1`, isAssertion: true, timeout: 1000
}
]
}
])
message.text.should.equal(`unsynchronized something 1`)
}).timeout(1000)
// TEST 2
it('should return unsynchronized something 2', async() => {
const message = await this.bot.usersInput([
{
user: 'someUserId',
channel: 'someChannel',
messages: [
{
text: `something 2`, isAssertion: true, timeout: 2000
}
]
}
])
message.text.should.equal(`unsynchronized something 2`)
}).timeout(2000)
something.js
controller.hears([`something (.*)`], ["direct_mention", "direct_message"], (bot, message) => {
let timeout = 0;
if(message.match[1] == '1'){
timeout = 1000
}else{
timeout = 2000
}
setTimeout(()=>{
bot.reply(message, `unsynchronized something ${message.match[1]}`)
}, timeout)
})
If the text is typed "something1", it takes 1000 ms for reply
If the text is typed "something2", it takes 2000 ms for reply
Abobe test result is that TEST 1 is passed, and TEST 2 get the error.
Because I got the message variable is {} on TEST 2.
If I set a config like {afterProcessingUserMessageTimeout: 2000} on controller.spawn, The both test will be passed.
it's too enough 2000ms for TEST 1, so I want to set a config of afterProcessingUserMessageTimeout on each input like the below.
it('should return unsynchronized something 2', async() => {
const message = await this.bot.usersInput([
{
user: 'someUserId',
channel: 'someChannel',
messages: [
{
text: `something 2`, isAssertion: true, timeout: 100, afterProcessingUserMessageTimeout: 2000
}
]
}
])
message.text.should.equal(`unsynchronized something 2`)
}).timeout(2000)
@yahsan2 thanks for example.
have you tried next structure:
[
{
text: `something`
},
{
text: '',
timeout: 2100,
isAssertion: true
}
]
a first object just provide your message to handler, a next one with empty text will wait about 2100
msec, like a afterProcessingUserMessageTimeout
timeout