← 返回 openai 的题目列表Design and implement an extensible ChatApp with bots (multi-channel support)
类型:online_judge
Coding: Implement an extensible ChatApp with bots (multi-bot extensibility; multi-channel support)
Implement a ChatApp class that processes user messages and bot responses.
Requirements
Basic chat
A user sends a message to a channel.
The system generates replies from registered bots (zero or more bot replies).
The system stores a message history (message log).
Extensibility (key point)
Adding a new bot type in the future should not require modifying existing core logic (open/closed principle).
The bot registration mechanism should be clear (registry/factory/plugin-style is acceptable).
Multi-channel support (follow-up)
Support multiple channelIds.
Each channel must have independent state:
its own message log;
its own bot state (for stateful bots).
Suggested interfaces (you may extend)
register_bot(bot)
send_message(channel_id, user_id, text)
get_messages(channel_id)
Constraints / assumptions
You may assume messages arrive in call order (no concurrency required), but the design should be extensible.
Bots may be stateless or stateful; your design must allow per-channel bot state.
Output
Provide ChatApp, a Bot abstraction, and at least 2 example bots (e.g., EchoBot, HelpBot).
Provide a minimal runnable demo: register bots → send messages in two channels → print each channel’s message history.
Data scale
#channels up to 1e4
messages per channel up to 1e5
#bots up to 1e2
No networking/database required; in-memory data structures are sufficient.
Example
Input
# demo
register: EchoBot, HelpBot
send: channel=A user=u1 text=hi
send: channel=B user=u2 text=help
print: channel=A
print: channel=B
Output
channel=A
u1: hi
EchoBot: hi
channel=B
u2: help
HelpBot: available commands: ...