cannot set the Sync document's ttl from a twilio function runtime client

290 Views Asked by At

I need my twilio sync documents to be deleted automatically after few minutes.

I followed the documentation for the Runtime.getSync(),

which by the way seems to be introduced here https://www.twilio.com/docs/runtime/client and extended by the "Documents" section here https://www.twilio.com/docs/sync/api/documents using node.js examples,

it was so hard to piece it all toghether.

but I cannot get the ttl parameter to work

exports.handler = function(context, event, callback) {

    let sync = Runtime.getSync();
    let payload = {
        'greeting': "bonbon!"
    };
    let uniqueName = "test4";

    sync.documents.create({
        uniqueName: uniqueName,
        ttl: 5, //////////////////DOESN'T WORK!!!
        data: payload
    }).then(function(response) {
        console.log(response);
        callback(null, response);
    });
}

the ttl parameter doesn't cause any effect on the expiration of the document and doesn't even cause the document's parameter "date_expires" (as seen in the https://www.twilio.com/docs/sync/api/documents ecample) to reflect the right value, in fact the date_expires parameter doesn't even appear in the returned JSON object:

{
_version: {
_domain: {
twilio: {
username: "xxxxxxxxxxxxxxxxxxxxxx",
password: "[Redacted]",
accountSid: "xxxxxxxxxxxxxxxxxxxxxx",
httpClient: { },
_sync: {
$ref: "$["_version"]["_domain"]"
}
},
baseUrl: "https://sync.twilio.com",
_v1: {
$ref: "$["_version"]"
}
},
_version: "v1"
},
sid: "xxxxxxxxxxxxxxxxxxxxxx",
uniqueName: "test4",
accountSid: "xxxxxxxxxxxxxxxxxxxxxx",
serviceSid: "xxxxxxxxxxxxxxxxxxxxxx",
url: "https://sync.twilio.com/v1/Services/xxxxxxxxxxxxxxxxxxxxxx/Documents/xxxxxxxxxxxxxxxxxxxxxx",
links: {
permissions: "https://sync.twilio.com/v1/Services/xxxxxxxxxxxxxxxxxxxxxx/Documents/xxxxxxxxxxxxxxxxxxxxxx/Permissions"
},
revision: "0",
data: {
greeting: "bonbon!"
},
dateCreated: "2018-09-19T03:30:24.000Z",
dateUpdated: "2018-09-19T03:30:24.000Z",
createdBy: "system",
_solution: {
serviceSid: "default",
sid: "xxxxxxxxxxxxxxxxxxxxxx"
}
}

is there anyone who has an explanation or a workaround? Thank you very much in advance

1

There are 1 best solutions below

1
On BEST ANSWER

Which version of twilio do you use?

https://www.twilio.com/console/runtime/functions/configure

If it is less than 3.6.10, ttl is not supported.

https://github.com/twilio/twilio-node/blob/master/CHANGES.md#2017-11-17-version-3100

[2017-11-17] Version 3.10.0

Sync

Add TTL support for Sync objects (breaking change)

The newest version is 3.21.0. Try it.