Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

User ID in send middleware with the Web adapter #2030

Open
cbouvard opened this issue Sep 11, 2020 · 7 comments
Open

User ID in send middleware with the Web adapter #2030

cbouvard opened this issue Sep 11, 2020 · 7 comments
Assignees

Comments

@cbouvard
Copy link

When using a send middleware with the Web adapter, the user ID is not available in the message object during a conversation (i.e. Dialog).
For instance, the middleware (bot, message, next) => { console.log(message); next(); } displays these data for a bot message:

{ type: 'message',
  text: 'typed!',
  inputHint: 'acceptingInput',
  channelData: {} }

A possible solution consists in extracting the user ID for the convo vars in the function makeOutgoing(dc, line, vars)
of conversation.ts:

// copy user and channel from vars (for Web adapter)
if (!outgoing.user && vars.user) {
    outgoing.user = vars.user;
}

Then the message user can be leverage in the send middleware 🎉

{ type: 'message',
  text: 'typed!',
  inputHint: 'acceptingInput',
  channelData: {},
  user: '7a247882-bdab-c853-7175-f97d3978d663' // <= Yes!
}

Moreover, when a message is sent with bot.reply or bot.say, the user ID is not present in the traditional (legacy?) messager.user.

{ type: 'message',
  text: 'Echo: pizza',
  // ...
  recipient: { id: '7a247882-bdab-c853-7175-f97d3978d663' },
  // ...
  user: '7a247882-bdab-c853-7175-f97d3978d663', // <= It would be great to have this
  // ...
}

It could be great to add it in the function ensureMessageFormat(message) of botworker.ts:

const activity = {
    type: message.type || 'message',
    text: message.text,
    // ...
    user: message.recipient && message.recipient.id, 
    // ...
};

Can these points be integrated in a future release of Botkit?
How can i make myself useful to the code?

Thanks,
Chris

Context:

  • Botkit version: 4.10.0
  • Messaging Platform: Web (botbuilder-adapter-web in version 1.0.9)
  • Node version: v10.15.1
  • Os: MacOS
@benbrown benbrown self-assigned this Sep 21, 2020
@benbrown
Copy link
Contributor

Can you please send these in as a pull request? And can you include some test cases when you do?

@cbouvard
Copy link
Author

Hi @benbrown!

I have just submitted the related tiny PR.

Finally I did not add user to the activity object in botworker.ts, to respect the Activity type. But the recipient field can be leverage in a send middleware to get the user.

So, with this fix, a send middleware like this can be done:

(bot, message, next) => {
    if (message && message.type === 'message') {
        const user =
            message.user ||
            (message.recipient && message.recipient.id);
        
        // => Store here the bot message for the given user
    }
    next();
}

@stale
Copy link

stale bot commented Nov 25, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Nov 25, 2020
@cbouvard
Copy link
Author

Hey!

I have just added a comment to the related PR (#2043) in order to remove the stale flag.

The code is working nicely in my chatbots powered by Botkit 🚀

I hope the next release of Botkit will integrate this PR.

Cheers,
Chris

@stale
Copy link

stale bot commented Jun 11, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Jun 11, 2021
@cbouvard
Copy link
Author

🆙 I still hope the next release of Botkit will integrate the related PR (#2043)...

@stale stale bot removed the stale label Jun 26, 2021
@stale
Copy link

stale bot commented Jan 9, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Jan 9, 2022
@benbrown benbrown removed the stale label Mar 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants