我的代码是:
import * as twilio from 'twilio';
import { IncomingCall } from '../models/IncomingCall';
const VoiceResponse = twilio.twiml.VoiceResponse;
export function incoming(requestBody: any): any {
const twiml = new VoiceResponse();
return IncomingCall.create({
CallSid: requestBody.CallSid,
From: requestBody.From,
To: requestBody.To,
rawData: requestBody
});
}
但是在执行new VoiceResponse()
时出现错误:
[ts] Cannot use 'new' with an expression whose type lacks a call or construct signature.
我正在使用Twilio v3.19.2
答案 0 :(得分:1)
您需要安装@types/twilio
软件包,其中包含twilio的类型定义。
运行npm install @types/twilio
(如果使用yarn,则运行yarn add @types/twilio
。
您可以了解有关@types/
软件包here的更多信息。
答案 1 :(得分:1)
请勿与new
一起使用,因为它不是构造函数。
运行npm install twilio
然后:
import * as Twilio from 'twilio';
const client = Twilio(accountSid, authToken);
const message = await client.messages.create({
body: 'This is the ship that made the Kessel Run in fourteen parsecs?',
from: twilioNumber,
to: phoneNumber
});
Twilio当前版本:“ ^ 3.49.0”