Render Slack Message Tokens Into Readable Mentions
Last updated: November 29, 2026
Quick Overview
Slack stores message text with encoded tokens like <@U123>, <#C456|general> and <!here>. Write a function that converts a raw message into display text using lookup maps of user IDs and channel IDs to current names.
Slack
November 29, 20260
0
0 solved
Slack stores message text with encoded tokens like <@U123>, <#C456|general> and <!here>. Write a function that converts a raw message into display text using lookup maps of user IDs and channel IDs to current names.
A warm-up in the style of Slack's phone screens, grounded in how the platform actually stores mentions so that renames do not break old messages. The interviewer is checking clean single-pass string parsing, sensible fallbacks for unknown IDs, and whether you ask about escaping.
What the Interviewer Expects
- Parse the text in one linear pass rather than repeated regex replacement on the output
- Handle user, channel, special broadcast and link tokens distinctly
- Fall back to the embedded label or a placeholder when an ID is missing from the map
- Treat an unmatched '<' as literal text
- State time and space complexity clearly
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- Slack escapes literal '<', '>' and '&' as HTML entities; where would you unescape, and why after tokenizing?
- How would you render a user who has been deactivated or a channel the viewer cannot see?
- How would you produce rich output (spans with click targets) instead of plain text?
- How would you go the other way and encode a typed '@ana' into a token at send time?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Input: raw text, users: {id: display_name}, channels: {id: name}. Tokens look like <@U1>, <@U1|label>, <#C9|general>, <!here>, <https://x|text>. Output plain display text. Unknown user I...
High-Level Design
Walk the string with an index. Copy plain runs up to the next <. On <, find the matching >; if none exists, the rest is literal. Split the token body on the first | into a reference and an opt...