/    Sign up×
Community /Pin to ProfileBookmark

TypeError: source.on is not a function

Hi,

I am not sure if it this is a correct place for my doubt, but i am a bit desperated
I have a working nodejs bot for Teams client, but I hope my problem is just a ‘javascfipt’ problem
I created my bot with Yeoman:

https://docs.microsoft.com/es-es/azure/bot-service/javascript/bot-builder-javascript-quickstart?view=azure-bot-service-4.0

Now I had a running example which can respond to an incoming message.
My problem is when I want to send a proactive message, I get this error:
“TypeError: source.on is not a function”
My complete code:

I have an index.js file, created automatically, and not modified
And my bot file (bot.js), created automatically, modified to add proactive messages
bot.js code:

“`
const { ConnectorClient, MicrosoftAppCredentials, BotConnector } = require(‘botframework-connector’);
const { ActivityHandler } = require(‘botbuilder’);

class MyBot extends ActivityHandler {

constructor() {
super();
// See https://aka.ms/about-bot-activity-message to learn more about the message and other activity types.
this.onMessage(async (context, next) => {
//await context.sendActivity(`You said ‘${context.activity.text}’`); // It works
var activity = context.activity;
await MicrosoftAppCredentials.trustServiceUrl(activity.serviceUrl);
var connectorClient = new ConnectorClient(credentials, { baseUri: activity.serviceUrl });
const parameters = {
members: [{ id: activity.from.id }],
isGroup: false,
channelData:
{
tenant: {
id: activity.conversation.tenantId
}
}
};
var conversationResource = await connectorClient.conversations.createConversation(parameters);

});
}

module.exports.MyBot = MyBot;
“`

In ‘createConversation’ is where I get the error:

[onTurnError]: TypeError: source.on is not a function

I have a stack trace of the error, and it seems to be related to ‘delayed stream’ node module. I add as a response since it is too long for a comment:

(node:28248) UnhandledPromiseRejectionWarning: TypeError: source.on is not a function
at Function.DelayedStream.create ([Bot Project Path]node_modulesdelayed-streamlibdelayed_stream.js:33:10)
at FormData.CombinedStream.append ([Bot Project Path]node_modulescombined-streamlibcombined_stream.js:45:37)
at FormData.append ([Bot Project Path]node_modulesform-datalibform_data.js:74:3)
at MicrosoftAppCredentials.refreshToken ([Bot Project Path]node_modulesbotframework-connectorlibauthmicrosoftAppCredentials.js:127:20)
at MicrosoftAppCredentials.getToken ([Bot Project Path]node_modulesbotframework-connectorlibauthmicrosoftAppCredentials.js:91:32)
at MicrosoftAppCredentials.signRequest ([Bot Project Path]node_modulesbotframework-connectorlibauthmicrosoftAppCredentials.js:71:38)
at SigningPolicy.signRequest ([Bot Project Path][email protected]:2980:44)
at SigningPolicy.sendRequest ([Bot Project Path][email protected]:2984:21)
at ConnectorClient.ServiceClient.sendRequest ([Bot Project Path][email protected]:3230:29)
at ConnectorClient.ServiceClient.sendOperationRequest ([Bot Project Path][email protected]:3352:27)

This code will be in a method, to call it when required, I put it in ‘onMessage’ just to simplify

I’m afraid I am missing something or doing sth wrong…

Any help will be great,

Diego

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@ddonateauthorOct 28.2019 — I found my problem. I must set credentials/conector/trust in the correct order:

credentials = new MicrosoftAppCredentials(process.env.MicrosoftAppId, process.env.MicrosoftAppPassword);

connectorClient = new ConnectorClient(credentials, { baseUri: activity.serviceUrl });

MicrosoftAppCredentials.trustServiceUrl(activity.serviceUrl);
×

Success!

Help @ddonate spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.21,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...