[英]How can I use Twilio node with TypeScript?
My code is:我的代码是:
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
});
}
But I get an error when doing new VoiceResponse()
:但是在执行
new VoiceResponse()
时出现错误:
[ts] Cannot use 'new' with an expression whose type lacks a call or construct signature.
I'm using Twilio v3.19.2我正在使用 Twilio v3.19.2
Don't use it with new
because it's not a constructor.不要将它与
new
一起使用,因为它不是构造函数。
Run npm install twilio
Then:运行
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 current version: "^3.49.0" Twilio 当前版本:“^3.49.0”
You need to install the @types/twilio
package which contains the type definitions for twilio.您需要安装包含 twilio 类型定义的
@types/twilio
包。
Run npm install @types/twilio
(or yarn add @types/twilio
if you use yarn).运行
npm install @types/twilio
(如果你使用 yarn,或者yarn add @types/twilio
)。
You can read more about the @types/
packages here .您可以 在此处阅读有关
@types/
包的更多信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.