Feat: Add Thread.thread() api to guarantee threading, otherwise defaults to message scope#374
Open
xtyler wants to merge 3 commits intovercel:mainfrom
Open
Feat: Add Thread.thread() api to guarantee threading, otherwise defaults to message scope#374xtyler wants to merge 3 commits intovercel:mainfrom
Thread.thread() api to guarantee threading, otherwise defaults to message scope#374xtyler wants to merge 3 commits intovercel:mainfrom
Conversation
Adds `thread.thread(messageId?)` as a means to officially support creating threads and guarantee a threaded response in channel-supporting platforms without impacting those that don't support channels. Adds openThread?(scopeId, messageId) as an optional method on the Adapter interface, following the openDM pattern, that returns an existing or new threadId.
…at, teams Add the newly supported openThread method to each adapter that supports thread creation/retrieval from a channel's messageId. GitHub, Linear, and WhatsApp omit openThread, thread() returns self. Removes Discord's auto-thread-creation on @mention, inconsistent with every other adapter. Removes Slack's auto-thread-creation on *all* @mentions and messages.
Streaming is used by default in thread.post() which is not supported within channels, add check for channel and accumulate stream to a single postMessage()
Contributor
|
@xtyler is attempting to deploy a commit to the Vercel Labs Team on Vercel. A member of the Team first needs to authorize it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds
thread.thread(messageId?)as a means to officially support creating threads and guarantee a threaded response in channel-supporting platforms without impacting those that don't support channels.This change reinforces Chat SDK's intended callback design where
onNewMention()andonNewMessage()return a thread representing the current message scope whether it's a channel or thread. Callingthread.subscribe()orthread.post()subscribes or posts to the thread or channel of the message. For consumers that wish to always respond in a thread,thread = await thread.thread()will return always return a thread, either itself if within a thread scope, or a new/existing thread from the latest message in the case of a channel.Without this there is tension resulting in inconsistent behavior between platform adapters, where Slack always creates new threads for every bot response, and Discord creates new threads on @mentions only. These are forced incorrect behaviors outside of a consumers control and were presumably implemented within the adapter to compensate for the lack of explicit thread creation. So we add
openThread?(scopeId, messageId)as an optional method on the Adapter interface, following the openDM pattern, that returns an existing or new threadId.Consumers can now choose when to guarantee a threaded response:
bot.onNewMention(async (thread, message) => {
const t = await thread.thread(); // will always return a thread, whether message is from channel or existing thread
await t.subscribe();
await t.post("Continuing in a thread.");
});
Warning: this change requires consumers who were previously relying on automatic thread creation for Slack and Discord to use the new API. It is a change to the behavior of these two adapters. Without this change, thread creation is automatic in these two adapters, a choice forced on the consumer. In Slack the consumer could feasibly use
thread.channel.post()as a workaround (with no easy way to know whether you're in a channel or thread scope), but in Discord @mention a thread is created and sits there empty regardless of whether you respond in that thread.Test plan
Unit tests on Chat SDK added for the new behavior. Slack and Discord adapter tests added for new
openThread()and modified for the fix in behavior. Discord, Slack, and Telegram were integrated and tested with live bots usingthread.post()and(await thread.thread()).post(), each working as expected.Chat SDK
openThreadAdapters (Discord and Slack)