Typing indicators

You can only work with typing indicators over WebSockets. They are a Signal packet; the body should contain the following fields:

Parameters:

Name Type Description
type string Value should be typing_indicator
object object Should contain an id field whose value is the conversation ID in which to send the typing indicator
request_id string (optional) Arbitrary ID to recognize a response
data object Should contain an action key, whose value is one of “started”, “paused”, or “finished”

Sending example:

{
 "type": "signal",
 "body": {
    "type": "typing_indicator",
    "request_id": "fred.flinstone.95",
    "object": {
      "id": "layer:///conversations/e67b5da2-95ca-40c4-bfc5-a2a8baaeb50f"
    },
    "data": {
      "action": "started"
    }
  }
}

Receiving example:

{
 "type": "signal",
 "timestamp": "2015-01-19T09:15:43+00:00",
 "body": {
    "request_id": "fred.flinstone.95",
    "type": "typing_indicator",
    "object": {
      "type": "Conversation",
      "id": "layer:///conversations/e67b5da2-95ca-40c4-bfc5-a2a8baaeb50f",
      "url": "https://api.layer.com/conversations/f3cc7b32-3c92-11e4-baad-164230d1df67"
    },
    "data": {
      "sender": BasicIdentity,
      "action": "started"
    }
  }
}

Discussion:

A client should update its typing indicator state every 2.5 seconds. As long as you consider the user to be actively typing, you should resend “started” every 2.5 seconds. After a lag of no activity, “paused” should be sent, and should continue to be sent every 2.5 seconds. Once “finished” is sent, no further typing indicators need to be sent to the server until the state has changed.

If the server doesn’t receive a state update from the client in time, the server will automatically transition to the next state. If “started” is sent to the server, and then no further states are sent, the server will automatically transition to “paused”. If the state is “paused” and no states are sent by the client, it will transition to “finished”.