Skip to main content
The Message Shortcuts extension stores short codes — !hb for “Happy birthday! 🎉” — for your app. This guide builds a formatter that lists the matching shortcuts when the user types !, and puts the expansion into the message when one is picked. Read Text Formatter Base Class first: this is a formatter with ! as its tracking character.

Steps

1. Fetch the shortcuts

The SDK calls back on its own queue, so bridge callExtension from a nonisolated function. The extension answers with a shortcuts dictionary of code → expansion:
ShortcutsAPI.swift

2. Create the ShortCutFormatter class

Fetch once, then filter locally as the user types. A picked item shows its expansion in the input — promptText — and sends it — underlyingText:
ShortCutFormatter.swift

3. Override the search method

search(_:) above is the whole contract: called with the text after ! while the user types, and with nil when the query ends — clear the list then. setShowLoadingIndicator(_:) shows the list’s spinner during the first fetch.

4. Override onScrollToBottom

The extension returns every shortcut at once, so there is nothing more to load: onScrollToBottom() stays empty.

5. Integrate with the Message Composer

ShortcutComposer.swift
Now typing !h lists the shortcuts that start with it; picking “Happy birthday! 🎉” puts it in the input, and that text is what is sent.

Next Steps

Text Formatter Base Class

Every hook a formatter has

Mentions Formatter

The built-in formatter

Extensions

The extensions the Kit supports

All Guides

Browse the other guides