I see there's a way to initiate a say: https://github.com/sundeepgupta/botkit#botsay
Is there a way to do something similar for a conversation or an ask?
Is startConversation() or startPrivateConversation() not what you are looking for?
In the docs, startConversation
Edit: Ahh, I see what you mean. Starting a conversation based on logic in the app, not in response to a user's message
You can call bot.startConversation( ) and pass in an object containing a known user's ID as the channel. In this instance you just have to know the ID ahead of time. You have to start a conversation in order to use the ask() function.
bot.startConversation({
user: <USER ID>,
channel: <USER ID>,
text: 'dummy'
}, function(err, convo) {
convo.ask({
channel: <USER ID>,
text: 'Just what do you think you are doing, Dave?'
}, function(res, convo) {
convo.say(res.text + ' is not a good enough answer.')
convo.next()
}
)
Excellent, thanks @jonchurch
@jonchurch Really grateful for this.... Finally, I got this feature to work for me. Thanks again!
This was what actually worked for me.
I had to initiate Slack's web API with bot.api.im.open -- this will allow you know the user channelID before hand.
Hear:
new CronJob('0 */1 * * * *', () => {
bot.api.im.open({
user: 'U2WQ0L9FW'
}, (err, res) => {
if (err) {
bot.botkit.log('Failed to open IM with user', err)
}
console.log(res);
bot.startConversation({
user: 'U2WQ0L9FW',
channel: res.channel.id,
text: 'WOWZA... 1....2'
}, (err, convo) => {
convo.say('This is the shit')
});
})
}, null, true, 'Africa/Lagos')
I can confirm @ewdave's answer. If I try it the way @jonchurch suggested, namely without bot.api.im.open, it will only post the first message, and no further messages or questions after that. Can anyone else confirm?
hey @ewdave did you get this to work? I'm getting a 'not_authed' error when i use bot.api.im.open...
Most helpful comment
This was what actually worked for me.
I had to initiate Slack's web API with
bot.api.im.open-- this will allow you know the user channelID before hand.Hear: