How to get the DisconnectTimestamp from Amazon Connect call in NodeJS

125 Views Asked by At

My call recordings are being pushed at S3 and stored with contactId_timestamp.wav as filename. For now i can get/download the files by specifically providing the file name as key, now i wanted to create the filename by myself as contactId + disconnecttimestamp i can get ge contactId through getContactId() but how to get the disconnecttimestamp?

My goal is same what we are experiencing in Contact Flow Search the recordings can be played with respect to contactId.

Here is how i am downloading the recordings from S3.

require("dotenv").config();
const expres = require("express");
const app = expres();

app.listen(3001);

const aws = require("aws-sdk");

aws.config.update({
    secretAccessKey: process.env.ACCESS_SECRET,
    accessKeyId: process.env.ACCESS_KEY,
    region: process.env.REGION
})

const BUCKET = process.env.BUCKET
const s3 = new aws.S3(secretAccessKey = process.env.ACCESS_SECRET, accessKeyId = process.env.ACCESS_KEY);

 app.get("/download/filename", async(req, res)=>{
    const filename = req.params.filename
    let x = await s3.getObject({Bucket:BUCKET, Key:filename}).promise();
    res.send(x.Body);
})

And Than hitting the http://localhost:3001/download/0989c085-16d1-478b-8858-1ccddb2990f4_20220303T16:46_UTC.wav

1

There are 1 best solutions below

0
On

If you have the ContactID for the call you can use describeContact to get the contact info which includes the DisconnectTimestamp.

Something along these lines should work.

const AWS = require('aws-sdk');

aws.config.update({
    secretAccessKey: process.env.ACCESS_SECRET,
    accessKeyId: process.env.ACCESS_KEY,
    region: process.env.REGION
})
const connect = new AWS.Connect({ region: process.env.REGION });

var params = {
  ContactId: 'STRING_VALUE', /* required */
  InstanceId: 'STRING_VALUE' /* required - the connect instance ID */
};

connect.describeContact(params, function(err, data) {
  if (err) console.log(err, err.stack); // an error occurred
  else var DisconnectTimestamp = data.Contact.DisconnectTimestamp);           // successful response
});

more info here https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/Connect.html#describeContact-property