Overview
Typing events are emitted when someone in a conversation starts or stops typing a message.
Events
typing-indicator
Emitted when a typing indicator appears or disappears in a conversation.
Typing indicator information
The unique identifier of the chat where typing is occurring
Whether the typing indicator should be displayed (true) or hidden (false)
import { SDK } from 'advanced-imessage';
const client = SDK();
client.on('typing-indicator', (data) => {
const status = data.display ? 'started' : 'stopped';
console.log(`Someone ${status} typing in chat: ${data.guid}`);
});
await client.connect();
Event Methods
on()
Register a listener that will be called every time the event is emitted.
client.on('typing-indicator', (data) => {
console.log(data);
});
once()
Register a listener that will be called only once, then automatically removed.
client.once('typing-indicator', (data) => {
console.log('First typing indicator:', data);
});
off()
Remove a specific listener from an event.
const handler = (data) => {
console.log(data);
};
client.on('typing-indicator', handler);
// Later, remove the listener
client.off('typing-indicator', handler);
You must pass the exact same function reference to off() that was passed to on(). Anonymous functions cannot be removed.
Important Notes
Typing indicators are not always reliable and may not fire in all situations:
- Group chats may not always show typing indicators
- SMS/MMS conversations (green bubbles) don’t support typing indicators
- Network conditions can delay or prevent typing events
- Some users may have typing indicators disabled in their settings
For better UX, implement a timeout to automatically hide typing indicators after 10-15 seconds, even if you don’t receive a display: false event.