Imagine adding notifications to an application that has already accumulated three vendor SDKs. Slack wants a channel, some text, and a bot flag. Teams expects a card title, a body, and a webhook URL. Discord asks for a numeric channel id, the message, and a text-to-speech flag. The application, meanwhile, just wants to say: “send this message to this recipient.”
Your task is deliberately focused: implement only SlackAdapter, TeamsAdapter, and DiscordAdapter. The common NotificationSender contract, all three service clients, and the NotificationHub test harness are already implemented in the starter code.
Every adapter implements send(recipient, message) and translates that call to one vendor API:
SlackAdapter(client) stores a SlackClient and calls postMessage(recipient, message, true).TeamsAdapter(webhook, webhookUrl) stores both values and calls sendCard(recipient, message, webhookUrl).DiscordAdapter(bot, channelId) stores both values and calls sendMessage(channelId, message, false). The shared recipient argument is not used for Discord because its destination was fixed when the adapter was created.
The service clients return the line they would have posted:
SlackClient.postMessage(channel, text, asBot) returns Slack -> #<channel>: <text> (bot=<asBot>)TeamsWebhook.sendCard(title, body, webhookUrl) returns Teams -> <webhookUrl>: [<title>] <body>DiscordBot.sendMessage(channelId, content, tts) returns Discord -> channel <channelId>: <content> (tts=<tts>)
Slack always posts as a bot, Discord never uses text to speech, and a Teams adapter keeps its webhook URL for later sends. Those service-specific details belong inside the adapters, not in the hub.
The provided NotificationHub registers your adapters, keeps them in one NotificationSender collection, validates indexes, broadcasts in registration order, and counts successful sends. The examples use hub operations because it is the public test harness; your code changes belong only inside the three adapter classes.
Example 1:
Input:
Output:
Explanation: One send call per channel produces three differently shaped lines. The hub passed a recipient and a message, and each adapter supplied everything else its service wanted.
Example 2:
Input:
Output:
Explanation: broadcast reaches both channels in registration order and counts two sends. The last call names index 5, which holds no channel, so it returns UNKNOWN.
Constraints
1 <= webhookUrl.length <= 601 <= recipient.length <= 301 <= message.length <= 600 <= channelId <= 1000000000-20 <= index <= 20- At most
100 calls in total are made across all methods.
Starter Code
Only the three adapter classes are unfinished. Define each complete adapter at its marked location. The shared contract, vendor clients, and hub are already implemented; do not rewrite them.