howdyai / botkit

Botkit is an open source developer tool for building chat bots, apps and custom integrations for major messaging platforms.
MIT License
11.48k stars 2.28k forks source link

How to pass user info at runtime? #1364

Closed Purus closed 6 years ago

Purus commented 6 years ago

I have read docs on booting with user info. As per my understanding this needs to be done in the public client JavaScript code.

How do I pass entire user object values from my botkit controller, maybe before start hearing on.

ouadie-lahdioui commented 6 years ago

@Purus WDYM by booting with user info ?

Purus commented 6 years ago

In my understanding we need to pass on user information to store them along work message. Please correct me if I am wrong.

On Thu, May 31, 2018, 11:03 PM Ouadie Lahdioui notifications@github.com wrote:

@Purus https://github.com/Purus WDYM by booting with user info ?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/howdyai/botkit/issues/1364#issuecomment-393611981, or mute the thread https://github.com/notifications/unsubscribe-auth/ABBx5-UM5Q3fMpjQRvbYdx5e8FO2PtQOks5t4ClxgaJpZM4USs3Q .

ouadie-lahdioui commented 6 years ago

which platform are you using (FB, Slack, WS, Web ...) ?

Purus commented 6 years ago

I am using web platform.

On Fri, Jun 1, 2018, 3:11 PM Ouadie Lahdioui notifications@github.com wrote:

which one are you using (FB, SLack, WS, Web ...) ?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/howdyai/botkit/issues/1364#issuecomment-393829411, or mute the thread https://github.com/notifications/unsubscribe-auth/ABBx57IZycIbIdpbdyvtitBBHNNHr5aaks5t4QwugaJpZM4USs3Q .

peterswimm commented 6 years ago

@Purus take a look at these docs for dealing with user data on the web client https://github.com/howdyai/botkit-starter-web/blob/master/docs/botkit_web_client.md#share-user-accounts--profile-data-with-botkit

Purus commented 6 years ago

Thanks @peterswimm . I have read those doc. But I want to pass the data from the bokit controller code as I have to do some LDAP calls to get the user info like name.

sudk97 commented 6 years ago

I have the same issue, can I by any means pass some values from the javascript where I embedded my bot on the web and use it in the controller to say validate the user and then respond accordingly?

adantoscano commented 6 years ago

@Purus @sudk97 you can add more keys: values to the object that you send to botkit from the frontend and then manage them with a middleware in botkit.

Purus commented 6 years ago

Any example on how to do this will be helpful.

On Mon, Jun 4, 2018, 3:52 PM Adán Toscano notifications@github.com wrote:

@Purus https://github.com/Purus @sudk97 https://github.com/sudk97 you can add more keys: values to the object that you send to botkit from the frontend and then manage them with a middleware in botkit.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/howdyai/botkit/issues/1364#issuecomment-394306638, or mute the thread https://github.com/notifications/unsubscribe-auth/ABBx56xvcSsYqOQ0iN-kjEU1N98SJ2dwks5t5QpWgaJpZM4USs3Q .

adantoscano commented 6 years ago

https://github.com/howdyai/botkit-starter-web/blob/e0cead4da1e0cf84ab9b12f432508e2d4365e865/public/client.js#L70

I copied the function from here and add the following...

        that.deliverMessage({
          type: 'message',
          text: text,
          user: this.guid,
          channel: this.options.use_sockets ? 'socket' : 'webhook'
          custom: 'Purus rocks!'
        });

then in botkit use middleware

controller.middleware.receive.use(function(bot, message, next) {
  console.log(message.custom); //Puru rocks!
  next();
});
sudk97 commented 6 years ago

Thanks a lot @adantoscano, worked for me :+1: