-
Notifications
You must be signed in to change notification settings - Fork 84
Send a message with the RTM API #50
Comments
np! there's no something like this would work tho var slack = require('slack')
var bot = slack.rtm.client()
var token = process.env.SLACK_BOT_TOKEN
// define a hello handler
bot.hello(msg=> {
// NOTE you need to set text and channel here
slack.chat.postMessage({text, channel, token}, console.log)
})
bot.listen({token}) |
Thanks Brian. The |
Ah! Yes you can do that too. (= Fwiw: we only use the Web API for replies. Sockets can manifest tricky state issues especially when you double duty them for send and receipt logic (even though they are duplex in nature). Anyhow: still possible and totally appropriate for many cases! To send a msg via the socket you can use var slack = require('slack')
var bot = slack.rtm.client()
var token = process.env.SLACK_BOT_TOKEN
// define a hello handler
bot.hello(msg=> {
// NOTE you need to set text and channel here
bot.ws.send({
"id": 1,
"type": "message",
"channel": "C024BE91L",
"text": "Hello world"
})
})
bot.listen({token}) More info about the JSON payloads look for "Sending messages" on this page: |
Also! https://github.com/smallwins/slack/blob/master/src/rtm.client.js |
LMK if this answers your questions / happy to help more if its still not working but closing this issue for now. Thx! |
Sounds silly but I'm struggling with this! I have a connection, can see the channels, users, etc but I cannot send a message. What am I doing wrong?
When I do that, nothing happens :( I've also tried with a properly formatted JSON (using quotes)
The text was updated successfully, but these errors were encountered: