Node-slack-sdk: Question - how to send the "typing.." message?

Created on 4 Jan 2016  Â·  16Comments  Â·  Source: slackapi/node-slack-sdk

I tried:

cient.emit('userTyping', userID, channel);

and:

channel.startedTyping(userID)

both didn't work.
Is there an example somewhere I can use?

docs

Most helpful comment

To answer the question about sending a message to indicate the bot is typing, use rtm.sendTyping:

rtm.sendTyping(channelId);

However, given that rtm._send didn't work, you likely are running into an issue with your channel ID not being correct or the RTM client not being connected yet.


How can you access the underlying RTM mechanism to do things that aren't officially supported by the SDK

Although this isn't the current case, if you wanted to send an unsupported message type through the RTM client, I'd suggest using rtm.send and not rtm._send as rtm.send has some helpful error checks (and could have more stuff in the future).

All 16 comments

Clients can send a typing indicator to indicate that the user is currently writing a message to send to a channel:

{
    "id": 1,
    "type": "typing",
    "channel": "C024BE91L"
}

This can be sent on every key press in the chat input unless one has been sent in the last three seconds. Unless there is an error the server will not send a reply, but it will send a "user_typing" event to all team members in the channel.

Thanks. So this is what happen when a _human_ user is writing a message.
My question was referring to a typing action from the _bot_.

The bot i'm working on connects to couple of services and it takes him 4 - 5 seconds to reply. I think It would be kinda cool to show "@bot is typing..." in the meanwhile

@l12s is right, I was able to get it to work by sending a command directly to the private client method.

var Slack = require("slack-client");
var slack = new Slack(token, true, true);
// login dance 
slack._send({id: 1,
  type: "typing",
  channel: "CHANNEL_ID"
});

Good luck and reopen if you need any more help!

@silentrob- I 'm trying to use the code you wrote and get:
ERROR TypeError: Slack is not a constructor

I'm using slack-client version "version": "2.0.6"

I think @silentrob 's instructions are for a much older version. Currently, it would look more like this, modified from the documentation:

var RtmClient = require('@slack/client').RtmClient;
var rtm = new RtmClient(bot_token);
rtm.start();
// you need to wait for the client to fully connect before you can send messages
rtm.on(RTM_CLIENT_EVENTS.RTM_CONNECTION_OPENED, function () {
    rtm._send({id: 1,
    type: "typing",
    channel: "CHANNEL_ID"
  });
});

You'll need to fill in bot_token and CHANNEL_ID on your own.

@DEGoodmanWilson big thank you :+1:
when I'm trying to do rtm.start() I get :
debug: { '0': 'unable_to_rtm_start', '1': 'missing_scope' }

well , I was needed to grant authorization to my slack app using
https://slack.com/oauth/authorize?
client_id=...&
scope=client
and that solved the problem, so rtm.start is working ..
but still it doesn't work for me. i send
rtm._send({id: 1,
type: "typing",
channel: "CHANNEL_ID"
});
and nothing happens ...

Just to check…you are replacing CHANNEL_ID with an actual channel ID?

Yes indeed

I'm going to recast this as a more general question about: How can you access the underlying RTM mechanism to do things that aren't officially supported by the SDK…because it looks like none of us, myself included, have the right notion of how this works…

To answer the question about sending a message to indicate the bot is typing, use rtm.sendTyping:

rtm.sendTyping(channelId);

However, given that rtm._send didn't work, you likely are running into an issue with your channel ID not being correct or the RTM client not being connected yet.


How can you access the underlying RTM mechanism to do things that aren't officially supported by the SDK

Although this isn't the current case, if you wanted to send an unsupported message type through the RTM client, I'd suggest using rtm.send and not rtm._send as rtm.send has some helpful error checks (and could have more stuff in the future).

The official documenation as seen here (at time of posting, 26 Nov, 2016 21:50 UTC): https://api.slack.com/methods/chat.postMessage

there is no support for the type field on posting messages. Could Slack have deprecated this option for bots?

Weird, official documentation for the RTM api shows the type field for sending a message indicating the bot is typing.

The feature is most definitely not deprecated ;)

@DEGoodmanWilson can you help us to figure out how to send an event so that our bots seem to be typing?

I answered how to do it earlier: rtm.sendTyping.

As noted in the botkit issue that references this issue, this only works with the RTM API currently. Why, I can't tell you, and it doesn't revolve around an issue with this repository.

If you'd like to question it then your best bet may be contacting Slack support and hoping to get to one of the super-cool Slack Engineers. They might already know about this, however.

Was this page helpful?
0 / 5 - 0 ratings