Comments (5)
np! there's no this
nor message
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})
from slack.
Thanks Brian. The postMessage
method is part of the Web API. I'm trying to send a message with the RTM API.
from slack.
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 bot.ws.send
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:
from slack.
Also! slack.rtm.client
above really is a super simple thin wrapper around ws
:
https://github.com/smallwins/slack/blob/master/src/rtm.client.js
from slack.
LMK if this answers your questions / happy to help more if its still not working but closing this issue for now. Thx!
from slack.
Related Issues (20)
- Changelog HOT 4
- No file for browser in npm package HOT 6
- Proxy handling HOT 4
- Typescript defs don't support OO style pattern HOT 16
- Can't Handle Errors Gracefully HOT 4
- Failed to minify / pkg command fails HOT 3
- Listen for messages using the RTM HOT 4
- How to I get the install jenkins app details? HOT 1
- Workspace Apps X-Slack-User HTTP header HOT 8
- proposal: more helpful stack traces HOT 3
- Not running in webpack target electron-renderer HOT 5
- Unable to post interactive messages using postMessage HOT 1
- `useElectronNet: true` doesn't work HOT 3
- Support for chat.scheduleMessage
- promise return twice HOT 3
- Sending duplicate messages
- Webpack support HOT 5
- Support for OAuth V2 endpoints (and possibly other new ones) HOT 2
- Support for undocumented API endpoints and custom headers HOT 1
- Compilation Errors HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from slack.