Search code examples
javascriptnode.jsbotframeworktypeerrorproactive-message

Resuming a conversation in Bot Framework throws TypeError: Cannot perform 'set' on a proxy that has been revoked


I'm playing with the Microsoft Teams Bot Framework samples, specifically bot-conversation (source)

I want to post user messages to a back-end via a websocket, then post a message to chat when I get a response.

I'm currently wiring the bot up as follows

class TeamsConversationBot extends TeamsActivityHandler {
    ws = null;

    constructor(adapter) {
        super();
        this.adapter = adapter;

        this.onMessage(async (context, next) => {
            //Outbound messages from user to back-end. Works fine.
            TurnContext.removeRecipientMention(context.activity);
            await context.sendActivity({ type: 'typing' });
            const text = context.activity.text.trim();

            await this.handleUserPrompt(context, text);
            await next();
        });


        this.ws = new WebSocket('wss://.../dev');
        this.ws.on('message', async (data) => {
            // Inbound message from back-end to user
            console.log('\nKhydra->Teams: ', data.toString('utf8'));
            const messageData = JSON.parse(data);
            await this.handleKhydraFragment(messageData);
        });
    }

And this is how I'm attempting to rehydrate the conversation when I get a text block to display.

    async handleKhydraFragment(messageData) {
        const fragment = messageData.fragment;
        if ('textBlock' in fragment) {
            const claimsIdentity = await this.adapter.createClaimsIdentity(process.env.MicrosoftAppId);
            await this.adapter.continueConversationAsync(claimsIdentity, messageData.conversationReference, async (context) => {
                context.sendActivity(fragment.textBlock);
            });
        } else {
            console.log(fragment);
        }
    }

Interestingly, the correct text is posted to the chat when a fragment with a textBlock arrives, however, immediately after that I get

E:\Source\Microsoft-Teams-Samples\samples\bot-conversation\nodejs\node_modules\botbuilder-core\lib\turnContext.js:392
                    this.responded = true;
                                   ^

TypeError: Cannot perform 'set' on a proxy that has been revoked
    at Proxy.<anonymous> (E:\Robora\Source\Microsoft-Teams-Samples\samples\bot-conversation\nodejs\node_modules\botbuilder-core\lib\turnContext.js:392:36)
    at Generator.next (<anonymous>)
    at fulfilled (E:\Robora\Source\Microsoft-Teams-Samples\samples\bot-conversation\nodejs\node_modules\botbuilder-core\lib\turnContext.js:9:58)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Node.js v18.15.0

What am I missing?


Solution

  • It looks like you forgot to await the context.sendActivity() call. Adding await should fix the problem.

    async handleKhydraFragment(messageData) {
            const fragment = messageData.fragment;
            if ('textBlock' in fragment) {
                const claimsIdentity = await this.adapter.createClaimsIdentity(process.env.MicrosoftAppId);
                await this.adapter.continueConversationAsync(claimsIdentity, messageData.conversationReference, async (context) => {
                    // ADD AWAIT TO THE FOLLOWING LINE, LIKE SO
                    await context.sendActivity(fragment.textBlock);
                });
            } else {
                console.log(fragment);
            }
        }