Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NodeJS Proactive Messaging in Bot-framework for Skill Bot

I am working on a requirement in NodeJS where I have to invoke proactive messages from Skill Bot. I have a set Interval loop which runs for every 8 seconds where I added adapter.ContinueConversation method. I have added the below code in skill bot on message method initially but I received 401 Unauthorized error.

await context.sendActivity(`Echo (JS) : '${ context.activity.text }'`);
await context.sendActivity('Say "end" or "stop" and I\'ll end the conversation and back to the parent.');
var adapter = context.adapter;
var conversationReference = TurnContext.getConversationReference(context.activity);
var refreshInterval = setInterval(async () => {
try {
     await adapter.continueConversation(conversationReference, async turnContext => {
        await turnContext.sendActivity('Are you still there?');
    });
} 
catch (error) {
 console.log(error);
}
}, 8000,conversationReference);

After doing some research online, i have added additional parameters like claims identity and Root Bot's App Id as below but now I receive error that adapter.continueConversationAsync is not a function

var conversationReference = TurnContext.getConversationReference(stepContext.context.activity);
var claimsIdentity= stepContext.context.turnState.get(stepContext.context.adapter.BotIdentityKey);    
var oAuthScope= stepContext.context.turnState.get(stepContext.context.adapter.OAuthScopeKey);

await adapter.continueConversationAsync(claimsIdentity, convRef, oAuthScope, async context => {    
      await context.sendActivity("hello");
  }) 

Can anyone please help resolve the issue?

like image 632
Sharvani Avatar asked Sep 23 '26 02:09

Sharvani


1 Answers

First, you're receiving the error, "adapter.continueConversationAsync is not a function" because your parameters are wrong. Per the docs there are two overloaded versions of the continueConversation method :

function continueConversation(reference: Partial<ConversationReference>, logic: (context: TurnContext) => Promise<void>): Promise<void>

and

function continueConversation(reference: Partial<ConversationReference>, oAuthScope: string, logic: (context: TurnContext) => Promise<void>): Promise<void>

Your initial implementation was fine, the problem isn't the lack of oAuthScope. I can think of three possible reasons why you get a 401 error :

  1. Your appID and appPassword for your bot adapter might not be set correctly. Verify your appId and appPassword is correct.

     const adapter = new BotFrameworkAdapter({
         appId: process.env.MicrosoftAppId,
         appPassword: process.env.MicrosoftAppPassword
     });
    
  2. Try trusting the service URL of the conversation reference :

     var conversationReference = TurnContext.getConversationReference(stepContext.context.activity);
    
     await adapter.continueConversationAsync(conversationReference, async context => {    
         MicrosoftAppCredentials.trustServiceUrl(conversationReference.serviceUrl);
         await context.sendActivity("hello");
     }) 
    

And finally, try logging your conversationReference and verify the conversationReference itself is correct. Although since you're getting the conversationReference from the turncontext right before sending the proactive message this part shouldn't be the issue.

like image 152
John Kim Avatar answered Sep 26 '26 09:09

John Kim



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!