PubNub Logo Docs
Support Contact Sales Login Try Our APIs

›MESSAGES

Collapse all
Dark mode

Back to Home

Overview

  • In-App Chat

Chat Components

  • Overview
  • REACT

    • React Components

    ANDROID

    • Getting Started
    • UI Components
    • UI Theming
    • Data Components
    • Chat Provider
    • Message Reactions
    • Message Menu

    IOS

    • Getting Started
    • UI Components
    • UI Theming
    • Data Components
    • Chat Provider

SDKs

  • Overview
  • USERS

    • Setup
    • Metadata
    • Permissions
    • Presence
    • Mentions

    CHANNELS

    • Types and Names
    • Metadata
    • Subscriptions
    • Memberships

    MESSAGES

    • Sending Messages
    • Message History
    • Unread Counts
    • File Upload
    • Typing Indicators
    • Read Receipts
    • Emoji Reactions
    • Update Messages
    • Delete Messages
    • External Storage

    PUSH NOTIFICATIONS

    • Overview

    MODERATION

    • Profanity Filters
    • Flag Messages
    • Ban Users
    • Mute Users
    • Spam Prevention

    INTEGRATIONS

    • Overview
    • Content Moderation
    • Image Moderation
    • Language Translation
    • Chatbots
    • GIFs
    • Stickers

Moderation Dashboard

  • Overview
  • Getting Started
  • FEATURES

    • Automatic Text Moderation
    • Automatic Image Moderation
    • Manual Message Moderation
    • Manual User Moderation
    • User Management
    • Channel Management
  • Required Configuration

Debug Console
Network Status

Typing indicator

Typing indicators enable you to indicate if users are typing messages in a channel. This feature is easy to implement and can significantly improve the experience for your users.

You can trigger a typing event when a user starts typing a message. Other users in the channel receive these events in real time to show typing indicators on the screen. Applications usually display a typing indicator for a few seconds before it expires, or continue display it if the user is still typing. The app hides the indicator when it receives the actual message.

For example, you could follow a pattern like this:

  • Send a typing_on event when the user starts typing.
  • Send another typing_on event if the user is still typing after 10 to 15 seconds.
  • Send a typing_off event if the user removes the message they were typing.

Send typing on/off events

Use the signal method to send transient events to indicate that a user is typing a message or has stopped typing.

By default, signals are limited to a message payload size of 64 bytes. This limit applies only to the payload, and not to the URI or headers. If you require a larger payload size, contact support. For more details on working with signals, refer to Sending Signals.

JavaScript
Swift
Java
Unity

Go to SDK

pubnub.signal({
message: 'typing_on',
channel: 'ch-1'
}, (status, response) => {
// handle status, response
});

Go to SDK

pubnub.signal(
channel: "ch-1",
message: "typing_on"
) { result in
switch result {
case let .success(response):
print("Successful Response: \(response)")
case let .failure(error):
print("Failed Response: \(error.localizedDescription)")
}
}

Go to SDK

pubnub.signal()
.message("typing_on")
.channel("ch-1")
.async(new PNCallback<PNPublishResult>() {
@Override
public void onResponse(PNPublishResult pnPublishResult, PNStatus pnStatus) {
if (pnStatus.isError()) {
Long timetoken = pnPublishResult.getTimetoken(); // signal message timetoken
} else {
pnStatus.getErrorData().getThrowable().printStackTrace();
}
}
});

Go to SDK

pubnub.Signal()
.Message("typing_on")
.Channel("ch-1")
.Execute(new PNPublishResultExt((result, status) => {
if (status.Error) {
Console.WriteLine(status.ErrorData.Information);
} else {
Console.WriteLine(result.Timetoken);
}
}));

Note that signals are transient, and are handled differently than regular messages. You can't fetch signals from storage, and you only receive the most recent signal from the buffer queue via a subscribe request.

Typing Indicator Events

Typing events are published on the same channel as the original message. To receive them, you subscribe to the channel and add a listener for signals.

{
    "actualChannel": null,
    "channel": "ch-1",
    "message": "typing_on",
    "publisher": "user-456",
    "subscribedChannel": "my_channel_1",
    "subscription": null,
    "timetoken": "14966804541029440"
}
←File UploadRead Receipts→
  • Send typing on/off events
  • Typing Indicator Events
© PubNub Inc. - Privacy Policy