0

twilio Functionsで電話をかける際にtwimlを定義するが、urlを指定せず直接twimlにて話すメッセージを定義したいです。
サンプルコードでは以下の用にあるが、from to を自身のものに修正し実行しても失敗してしまう。
なぜtwimlの直指定ができないか教えてほしいです。

https://www.twilio.com/docs/serverless/functions-assets/quickstart/make-a-call

exports.handler = function (context, event, callback) {
// The pre-initialized Twilio Client is available from the `context` object
const twilioClient = context.getTwilioClient();

// Query parameters or values sent in a POST body can be accessed from `event`
const from = event.From || '+15017122661';
const to = event.To || '+15558675310';
// Note that the provided TwiML can be serialized as a string and sent!
const twiml = event.Twiml || '<Response><Say>Ahoy there!</Say></Response>';

// Use `calls.create` to place a phone call. Be sure to chain with `then`
// and `catch` to properly handle the promise and call `callback` _after_ the
// call is placed successfully!
twilioClient.calls
    .create({ to, from, twiml })
    .then((call) => {
    console.log('Call successfully placed');
    console.log(call.sid);
    // Make sure to only call `callback` once everything is finished, and to pass
    // null as the first parameter to signal successful execution.
    return callback(null, `Success! Call SID: ${call.sid}`);
    })
    .catch((error) => {
    console.error(error);
    return callback(error);
    });
};

レスポンスは以下

Error: Url parameter is required.

1 件の回答 1

2

自己解決しました

importされている twilio moduleが古かったこと。
moduleは初回deploy時に自動で定義されるが、それだと 3.29.2。
このバージョンはtwimlで定義できない。
最新の4.7.2にアップデートして解決。

この質問に回答するには、ログインする必要があります。

求めていた回答ではありませんか? のタグが付いた他の質問を参照する。