node.jscircuit-sdk

How to get email of user who send message to bot in Circuit JavaScript SDK?


I'm creating a bot that will receive a messages in Circuit and then send it somewhere else with email of user that printed this message.

As example I use xlator-bot https://github.com/circuit/xlator-bot

this.receiveItem = function receiveItem(item) {
        logger.info('[APP]: receiveItem');

        if (item.type !== 'TEXT' || self.sentByMe(item)) {
            logger.debug('[APP]: skip it is not text or I sent it');
            return;
        }

        if (!item.text || !item.text.content) {
            logger.info('[APP]: skip it does not have text');
            return;
        }

        self.receiveText(htmlToText.fromString(item.text.content))
            .then (function addResponseItem(responseItem){
                logger.info('[APP]: addResponseItem');
                var comment = {
                    convId: item.convId,
                    parentId: (item.parentItemId) ? item.parentItemId : item.itemId,
                    content: responseItem
                };
                return client.addTextItem(item.convId, comment);
            })
            .catch(function(e){
                logger.error('[APP]:', e);
            });
    };

I want to get email of user who send item in this function as string variable. Can anyone suggest how can I do it?


Solution

  • The item has an attribute creatorId which is the userId of the sender. The API getUserById will return the user object that contains the emailAddress attribute.

    See https://circuitsandbox.net/sdk/classes/Item.html#property_creatorId and https://circuitsandbox.net/sdk/classes/Client.html#method_getUserById and https://circuitsandbox.net/sdk/classes/User.html#property_emailAddress