Timbo13
Timbo13

Reputation: 11

Proactive Teams message - trustServiceUrl The "url" argument must be of type string

I'm trying to send a proactive teams message to an existing conversation using node.

Have installed bot for a user as per method described within https://learn.microsoft.com/en-us/microsoftteams/platform/graph-api/proactive-bots-and-messages/graph-proactive-bots-and-messages?tabs=javascript and also retrieved the conversation chatId.

My aim is to create a "console" style application where I can push a proactive message to this conversation, but am stuck with passing a valid URL through to the trustServiceUrl method and observe the following error:

TypeError [ERR_INVALID_ARG_TYPE]: The "url" argument must be of type string. Received type undefined

Sample code:

const path = require('path');
const botbuilder = require('botbuilder');
const ENV_FILE = path.join(__dirname, '.env');
require('dotenv').config({ path: ENV_FILE });

const { MicrosoftAppCredentials } = require('botframework-connector');

const adapter = new botbuilder.BotFrameworkAdapter({
    appId: process.env.MicrosoftAppId,
    appPassword: process.env.MicrosoftAppPassword
});

async function Main() {
    var conversationRef = '[MY TEAMS CONVERSATION REFERENCE]';
    let response = await sendMessage(conversationRef);
}

function sendMessage(conversationRef) {
    var promise = new Promise(function(resolve, reject) {
        adapter.continueConversation(conversationRef, async turnContext => {
            const serviceUrl = 'https://smba.trafficmanager.net/uk/';
            MicrosoftAppCredentials.trustServiceUrl(serviceUrl);
            await turnContext.sendActivity('proactive hello');
        });
    });

    return promise;
}

Main();

I know I'm overlooking something obvious, but am stuck with the above error - appreciate any steer.

Thanks!

Trace below:

(node:16504) UnhandledPromiseRejectionWarning: TypeError [ERR_INVALID_ARG_TYPE]: The "url" argument must be of type string. Received type undefined
    at validateString (internal/validators.js:118:11)
    at Url.parse (url.js:159:3)
    at Object.urlParse [as parse] (url.js:154:13)
    at Function.trustServiceUrl (C:\dev\demo\botFramework\node_modules\botframework-connector\lib\auth\appCredentials.js:68:25)
    at BotFrameworkAdapter.<anonymous> (C:\dev\demo\botFramework\node_modules\botbuilder\lib\botFrameworkAdapter.js:153:57)
    at Generator.next (<anonymous>)
    at C:\dev\demo\botFramework\node_modules\botbuilder\lib\botFrameworkAdapter.js:14:71
    at new Promise (<anonymous>)
    at __awaiter (C:\dev\demo\botFramework\node_modules\botbuilder\lib\botFrameworkAdapter.js:10:12)
    at BotFrameworkAdapter.continueConversation (C:\dev\demo\botFramework\node_modules\botbuilder\lib\botFrameworkAdapter.js:139:16)
(node:16504) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:16504) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
PS C:\dev\demo\botFramework>

Upvotes: 1

Views: 612

Answers (2)

Timbo13
Timbo13

Reputation: 11

See comments from @mdrichardson - my reference was not well formed and did not include all of the required properties.

Upvotes: 0

mdrichardson
mdrichardson

Reputation: 7241

Please ensure that your conversationRef has a serviceUrl property. It's likely the same one that you set for trustServiceUrl()

Upvotes: 0

Related Questions