Multiple Continuous API Requests Issue
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 35/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- react, typescript
- Domain
- frontend
Research direction
Start by reproducing the behavior with the supplied React subscription code and inspect how often subscribeToBotMessages is invoked and how activity$ subscriptions are created. Compare the resulting network requests with activity$ emissions and confirm that requests occur only when new messages are received, without duplicate subscriptions.
Written by the indexing model from the issue text.
Description
I have created a WebChat UI in React using the botframework-directlinejs package. While subscribing to messages, the application is continuously sending multiple API requests. This is leading to performance issues and unnecessary load on the server.
Expected Behavior:
The application should only send API requests when necessary, such as when new messages are received.
Actual Behavior:
The application is continuously sending multiple API requests, as shown in the attached screenshot.
my code :
const subscribeToBotMessages = useCallback(() => {
if (!directLine) return;
directLine.connectionStatus$.subscribe((status) => {
if (status === 2 && !conversationId) {
localStorage.setItem("conversationId", directLine.conversationId);
localStorage.setItem("token", directLine.token);
localStorage.setItem("watermark", directLine.watermark);
}
});
directLine.activity$
.filter(
(activity) =>
activity.type === "message" && activity.from.id !== "myUserId"
)
.subscribe((message) => {
const timestamp = new Date().toLocaleTimeString([], {
hour: "2-digit",
minute: "2-digit",
});
const newBotMessage = {
from: "bot",
botMessage: message,
timestamp,
liked: false,
disliked: false,
attachment:
message.attachments && message.attachments.length > 0
? message.attachments.length === 1 && message.attachments[0]
: null,
carousel:
message.attachments && message.attachments.length > 0
? message.attachments.length > 1 && message.attachments
: null,
};
setLoading(false);
if (message.text) {
try {
receiveAudioRef.current.play();
} catch (error) {
console.log("failed to play", error);
}
}
setMessages((prevMessages) => [...prevMessages, newBotMessage]);
});
directLine.activity$
.filter(
(activity) =>
activity.type === "message" && activity.from.id === "myUserId"
)
.subscribe((message) => {
const timestamp = new Date().toLocaleTimeString([], {
hour: "2-digit",
minute: "2-digit",
});
const newUserMessage = {
from: "user",
userMessage: message,
timestamp,
attachment: filePreview,
};
setMessages((prevMessages) => {
// Check if the user message already exists
if (
prevMessages.some(
(msg) => msg.timestamp === timestamp && msg.from === "user"
)
) {
return prevMessages;
}
return [...prevMessages, newUserMessage];
});
});
}, [directLine, conversationId]);
@billba
- Dominant language
- TypeScript
- Stars
- 199
- Forks
- 133
- PR merge metrics
- No merged PRs in 30d
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from microsoft/BotFramework-DirectLineJS
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
-
Difficulty 4/5 3-5 days Newbie friendliness 25/100
-
Difficulty 4/5 3-5 days Newbie friendliness 30/100
microsoft/BotFramework-DirectLineJS#432 · 1 reaction ·
-
bug
microsoft/BotFramework-DirectLineJS#421 · 3 comments · 1 assignee ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 35/100
microsoft/BotFramework-DirectLineJS#418 · 7 comments · 7 reactions ·
All issues in microsoft/BotFramework-DirectLineJS
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
copse-dev/agent-pane#2953 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
Eynzof/Hermes-CN-Desktop#610 ·
-
bug clawsweeper:linked-pr-open clawsweeper:needs-live-repro clawsweeper:no-new-fix-pr impact:message-loss issue-rating: 🐚 platinum hermit P2 regression
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
calcite-components needs triage refactor
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Esri/calcite-design-system#15203 ·