Skip to content

Sending a "typing" indicator in v2 using rtmclient.typing is not immediate #415

@alaaalii

Description

@alaaalii

Description

When using rtmclient.typing(channel), the typing indicator is not immediately sent, and is instead sent after message is posted.

What type of issue is this? (place an x in one of the [ ])

  • bug
  • enhancement (feature request)
  • question
  • documentation related
  • testing related
  • discussion

Requirements (place an x in each of the [ ])

  • I've read and understood the Contributing guidelines and have done my best effort to follow them.
  • I've read and agree to the Code of Conduct.
  • I've searched for any related issues and avoided creating a duplicate issue.

Bug Report

I'm trying to send a typing indicator while the user waits for my bot to respond, but doing so in v2 does not actually send a typing indicator until after my bot responds.

Using SlackClient v2, you can reproduce it using the code below: send the bot Hello, and after 2 seconds you receive the Hi @<user> message followed by the the typing indicator <bot> is typing.

#slackclient v2
import time
import slack

rtmclient = slack.RTMClient(token="xoxb-XXXX")

@slack.RTMClient.run_on(event='message')
def say_hello(**payload):
    data = payload['data']
    if 'text' in data and 'Hello' in data['text']:
        channel_id = data['channel']
        ts = data['ts']
        user = data['user']
        webclient = payload['web_client']

        # send a typing indicator
        rtmclient.typing(channel=channel_id)

        # simulate the bot taking a long action
        time.sleep(2)

        # send a message back using as_user=True
        webclient.chat_postMessage(
            channel=channel_id,
            text="Hi <@{}>!".format(user),
            ts=ts,
            as_user=True
        )

rtmclient.start()

This is weird behavior because my code is sending the typing indicator before sending the message, it's definitely confusing to the user :).

Using SlackClient v1 (v1.3.1 and python 2.7.15), doing the same thing works as expected: with the code below, send the bot Hello, you'll receive the typing indicator, receive the Hi @<user> after 2 seconds, and the indicator immediately disappears.

#slackclient v1
import time

from slackclient import SlackClient

client = SlackClient(token="xoxb-XXXX")


def say_hello(data):
    if 'text' in data and 'Hello' in data['text']:
        channel_id = data['channel']
        ts = data['ts']
        user = data['user']

        # send a typing indicator
        client.server.send_to_websocket({"id": 1, "type": "typing", "channel": channel_id})

        # simulate the bot taking a long action
        time.sleep(2)

        # send a message back using as_user=True
        client.api_call('chat.postMessage',
            channel=channel_id,
            text="Hi <@{}>!".format(user),
            ts=ts,
            as_user=True
            )


if client.rtm_connect():
    while client.server.connected is True:
        for data in client.rtm_read():
            if "type" in data and data["type"] == "message":
                say_hello(data)
else:
    print("Connection Failed")

Reproducible in:

slackclient version: 2.0.1

python version: 3.7.3

OS version(s): macOS 10.14.4

Steps to reproduce:

  1. Run the first code snippet above (the one that starts with #slackclient v2
  2. Send the bot Hello
  3. Observe the <bot> is typing indicator, you only see it after the bot replies back

Expected result:

A <bot> is typing indicator to be sent immediately when I do rtmclient.typing(channel=channel_id), and that the indicator disappears immediately after the bot replies back if the indicator was still present at the time.

Actual result:

The <bot> is typing indicator is not sent immediately when I do rtmclient.typing(channel=channel_id) and is instead sent after I post a message.

Attachments:

None

Metadata

Metadata

Assignees

Labels

Version: 2xbugM-T: A confirmed bug report. Issues are confirmed when the reproduction steps are documented

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions