无法从 twilio 函数运行时客户端设置同步文档的 ttl

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

我需要在几分钟后自动删除我的 twilio 同步文档。

我遵循了 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.

但我无法使 ttl 参数起作用

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);
    });
}

ttl 参数不会对文档的过期产生任何影响,甚至不会导致文档的参数 "date_expires"(如 https://www.twilio.com/docs/sync/api/documents 示例中所示)反映正确值,实际上 date_expires 参数甚至没有出现在返回的 JSON 对象中:

{
_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"
}
}

有没有人有解释或解决方法? 非常感谢您

您使用哪个版本的 twilio?

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

如果低于3.6.10,则不支持ttl。

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)

最新版本为3.21.0。试试吧。