Im using botbuilder framework with nodejs to build a teams bot. At the moment im trying to stream the text back to the user so they dont have to wait for the full response.
Currently im facing an issue with the context being lost on the .on component of the stream.
How do i keep the context inside of the data.on stream?
the context Outside: console gives me the turnContext, however once inside the data.on stream I do not have access to the context and it states its revoked. Is there a way to stream the response back to the user?
try {
const data = await postDataToEndpoint(url, reqBody, headers);
const capturedContext = context;
let payloadText;
console.log('context Outside: ', capturedContext)
data.on('data', async (chunk) => {
console.log('context: ', capturedContext)
await capturedContext.updateActivity(MessageFactory.text(`${payloadText}`));
await next()
}
} catch (err) {
const errorCardData: ErrorCardData = { error: err.message };
const errorCardJson =
AdaptiveCards.declare(errorCard).render(errorCardData);
await context.sendActivity(
MessageFactory.attachment(
CardFactory.adaptiveCard(errorCardJson)
)
);
await next();
}
```