Giter Site home page Giter Site logo

Comments (5)

brianleroux avatar brianleroux commented on May 17, 2024

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.

gazpachu avatar gazpachu commented on May 17, 2024

Thanks Brian. The postMessage method is part of the Web API. I'm trying to send a message with the RTM API.

from slack.

brianleroux avatar brianleroux commented on May 17, 2024

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:

https://api.slack.com/rtm

from slack.

brianleroux avatar brianleroux commented on May 17, 2024

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.

brianleroux avatar brianleroux commented on May 17, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.