0

I'm trying to do some analytics on average response time from some of our users on Twilio Chat.

I'm iterating through my channels, and I'm able to pull the info about messages, so I can compare times a message went un-responded to. However, I can't determine which users were in the channel at that time.

Is there anything on the channel that would give me historic member data? Who was in the channel? The channel.messages().list() method is only giving me the text of the messages sent to the channel and who it was by, but the user who may have been in a channel to respond changes throughout a channel's life time.

This is on the backend using the node.js SDK. note: This isn't a complete implementation for what I'm trying to do, but taking it in steps to get access to the information I'd need to do this. Once I have these messages and know which users are supposed to be in a channel at a given time, I can do the analytics to see how long it took for the users I am looking for to respond.

var fs = require('fs');
const Twilio = require('twilio');
const client = new Twilio(env.TWILIO_ACCOUNT_SID, env.TWILIO_AUTH);
const service = client.chat.services(env.TWILIO_IPM_SERVICE_SID);

async function getChatMessages() {
    const fileName = 'fileName.csv';
    const getLine = message => { 
        return `${message.channelSid},${message.sid},${message.dateCreated},${message.from},${message.type},${message.body}\n`;
    }
    const writeToFile = message => { fs.appendFileSync(fileName, getLine(message)); };
    const headerLine = `channelSid,messageSid,dateCreated,author,type,body`;
    fs.writeFileSync(fileName, headerLine);
    await service.channels.each(
        async (channel, done) => {
            i++;
            let channelSid = channel.sid;
            if( channel.messagesCount == 0 ) return;
            try {
                await channel.messages().list({limit:1000, order:"asc"}).then(
                    messages => {
                        messages.forEach( writeToFile );
                    }
                );
            } catch(e) {
                console.log(`There was an error getting messages for ${channelSid}: ${e.toString()}`);
            }
            if( i >= max ) done();
        }
    );
}

I'm beginning to be resigned to the fact that maybe this would only have been possible to track had I set up the proper event listeners / webhooks to begin with. If that's the case, I'd like to know so I can get that set up. But, if there's any endpoint I can reach out to and see who was joining / leaving a channel, that would be ideal for now.

halfer
  • 19,824
  • 17
  • 99
  • 186
Jake T.
  • 4,308
  • 2
  • 20
  • 48

1 Answers1

0

The answer is that unfortunately you can not get this data retroactively. Twilio offers a webhooks API for chat which you can use to track this data yourself as it happens, but if you don't capture the events, you do not get access to them again.

Jake T.
  • 4,308
  • 2
  • 20
  • 48