All the functionality I see is for botkit to REPLY to someone. Is there functionality to allow botkit to start messaging someone without being messaged first?
At a certain time of day, I would like to have my bot automatedly direct message everyone on my team, and THEN the bot should listen to and reply to their responses.
I can use Slack's webAPI to issue a chat.privatemessage to a user, but these messages will just go to the user's slackbot channel, and my bot won't hear messages in that slackbot channel....
Any thoughts on how to accomplish something like this? Thanks!
Yes, you can use the bot.say command to send messages without receiving one first.
However, you will need a valid channel ID to do so...
Thanks Ben,
I saw that in the documentation two days ago (>< very, very sorry) and added it.
I'm using bot.api.im.open to get the DM channel between the user and the bot, and then use bot.say to
This works great if messages need to be sent out in the next few minutes.
However, the following day, it appears that my bot sends some of the messages to users that it has stored, and then it goes offline... my bot nodejs script is still running, but I think maybe I am experiencing websocket disconnection... Do I need to be sending "ping" messages back and forth over RTM, as described here: https://api.slack.com/rtm ? If so, do you have any example code you could provide? Or, does botkit take care of this requirement automatically?
Thanks again for your time!
Yes, I think implementing the ping is a good idea. There seem to be occasions when bots get silently disconnected.
Thanks! Do you have any example code about how to send these RTM pings via the bot? I'm not seeing anything in the example documentation regarding sending RTM messages, nor anything in the documentation about RTM messages and "type": "ping" ...
Do you recommend I just pull the websocket url from the RTM connect response, and ping it on my own?
Not that I'm complaining about free botkit software, but maybe you might want to add something to that effect about this to the documentation... this way people know websocket connection keepalive is not handled internally by BotKit...
Thanks again!
Hi @swilsonian Do you seem to have found a way to go about initiating a message to a user with BotKit?
I'm currently working on a similar project and would love some help on that front. Thanks
cc @benbrown
So I found a way to go about this, just incase anyone's looking out for this.
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')
@ewdave When I try your way, it says back "Error: Cannot use web API to send messages.".
Do you have any idea why?
Figured it out with the bot initialized by the startRTM :)
I have tried the thing what @ewdave said, But I was getting cannot dm_bot error. Can anyone please tell me how we can solve this
@ewdave Do we need to close im or close convo after the above code or is that automatically handled ?
@alexisohayon I'm running into the same issue "Error: Cannot use web API to send messages.", can you elaborate on this:
Figured it out with the bot initialized by the startRTM :)
I got this error because the bot was not authenticated.
var bot = controller.spawn({
token: "......."
});
bot.say({
text: 'Test',
channel: 'XXXXXXX' // a valid slack channel, group, mpim, or im ID
});
The token you get it from https://api.slack.com/ > OAuth & Permissions > Bot User OAuth Access Token
Most helpful comment
So I found a way to go about this, just incase anyone's looking out for this.
I had to initiate Slack's web API with
bot.api.im.open-- this will allow you know the user channelID before hand.Hear: