question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

User Id same as Conversation Id

See original GitHub issue

Hello,

Last week (2017/03/03) I created a NodeJS bot in Azure using “Basic” template and configure DirectLine channel.

I added this code in bot:

bot.on('lookupUser', function (address) {
    if (address) {
        var message = new builder.Message().address(address).text(JSON.stringify(address));
        bot.send(message, function (err) {});
    }
});

…to get a first message from bot including the deserialized address object with user and conversation ids. The client code to embed WebChat control in index.html is:

BotChat.App({
  directLine: { secret: 'DIRECTLINE_SECRET_FROM_BOT_FRAMEWORK' },
  user: { id: 'TOKEN_ID', name: 'User' }
}, document.getElementById("bot"));

Then, I got ‘TOKEN_ID’ in the bot message. That code works until 2017/03/03!

So, today (2017/03/06) I am receiving as user id the same value as conversation id. I tried creating a new bot and new secrets, but no way to get user id from BotChat.App again.

¿Something wrong in my code? ¿Something changed in DirecLine?

Thank you.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
billbacommented, Mar 7, 2017

By the way, you shouldn’t have to wait for the connectionStatus to change to Online. postActivity does this internally. (Please let me know if it doesn’t). Also you don’t need to send from: { id: conversationId }, you can send the actual user id you want. UPDATE: I just tried this and indeed postActivity waits for connectionStatus to change to Online and then posts.

2reactions
inmarktechcommented, Mar 7, 2017

Thanks @billba and @dandriscoll for your feedback. I resolved what I need (send data to bot before start the conversation) using this code in client:

var params = BotChat.queryParams(location.search);
var my_token = params['my_token'];

var botConnection = new BotChat.DirectLine({
	secret: 'DIRECTLINE_SECRET'
});

BotChat.App({
	botConnection: botConnection
	,user: { id: 'USER_ID', name: 'User' }  // user.id auto updates after first user message
}, document.getElementById("bot"));

botConnection.connectionStatus$.subscribe(function (status) {
	if (status == 2) {  // wait for connection is 'OnLine' to send data to bot
		var convID = botConnection.conversationId;
		botConnection.postActivity({
			from: { id: convID }  // because first time user ID == conversation ID
			,type: 'event'
			,name: 'registerUserData'    // event name as we need
			,value: my_token   // data attached to event
		}).subscribe(function (activityId) {
			// This subscription is a MUST
			// If I remove this handler the postActivity not reaches the bot
		});
	}
});

Then, in bot code I added this middleware code to get data:

bot.use({ receive: function(event, next) {
    if (!!event && !!event.address && event.name == 'registerUserData') {
        var message = new builder.Message().address(event.address).text('my_token:' + event.value);
        bot.send(message, function (err) {});  // simulate proactive message to user
    }
    next();
} });
Read more comments on GitHub >

github_iconTop Results From Across the Web

User Id same as Conversation Id · Issue #357 - GitHub
Before the client sends any messages, this code fires and shows the user.id as the conversationID . So far as I know this...
Read more >
Conversation ID | Docs | Twitter Developer Platform
The conversation_id field is always the Tweet ID of the original Tweet in the conversation reply thread. All Tweets within the same reply...
Read more >
Guide to IDs in the Bot Framework - Bot Service | Microsoft Learn
Ordinal equality doesn't necessarily establish that two conversation IDs are the same conversation, although in most cases, it does. Activity ID.
Read more >
Conversation ID, message ID, and links - Front Help Center
Conversation ID: This is an alphanumeric identifier that can be used to locate a conversation. When writing into our support team, please send ......
Read more >
how to check if user id or conversation id or user alreadt exists ...
User message comes in (including userId and conversationId) · fetch user's conversation · if len(response['messages']) == 1 (messages in the ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found