mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-03-29 00:18:20 +08:00
Twilio tweaks (#12109)
* Cleanup Imports These should be uniform, and should all use the require() syntax, as they’re referring to common js modules. * Enable client.calls.list() * Split up RestMethod signature By splitting up the union into an overload, we get much more useful autocomplete info. * Remove BaseRequestCallback BaseRequestCallback was only used in RestMethod, and it’s incorrect: the user’s callback is always called with 3 arguments. I think this was an attempt to say that the user’s callback doesn’t need to specify a third argument, but a two-argument callback will already conform to RequestCallback anyway. As the updated tests show, this change gives us better type inference too. * Use new Node HTTP Interface This MiddlewareFunction type isn’t assignable to an express middleware otherwise, as the latest express-static-core type declarations removes Http.ServerRequest from the type definition of an express RequestHandler
This commit is contained in:
18
twilio/index.d.ts
vendored
18
twilio/index.d.ts
vendored
@@ -6,11 +6,9 @@
|
||||
/// <reference types="express" />
|
||||
/// <reference types="node" />
|
||||
/// <reference types="q" />
|
||||
|
||||
import * as Express from 'express';
|
||||
import * as Http from 'http';
|
||||
|
||||
import Q = require('q');
|
||||
import Express = require("express");
|
||||
import Http = require("http");
|
||||
import Q = require("q");
|
||||
|
||||
declare interface twilio {
|
||||
(sid?: string, tkn?: string, options?: twilio.ClientOptions): twilio.RestClient;
|
||||
@@ -52,9 +50,11 @@ declare namespace twilio {
|
||||
}
|
||||
|
||||
export interface RequestCallback { (err: any, data: any, response: Http.ClientResponse): void; }
|
||||
export interface BaseRequestCallback { (err: any, data: any): void; }
|
||||
|
||||
export interface RestMethod { (args: any | BaseRequestCallback, callback?: RequestCallback): Q.Promise<any>; }
|
||||
export interface RestMethod {
|
||||
(callback: RequestCallback): Q.Promise<any>;
|
||||
(args: any, callback?: RequestCallback): Q.Promise<any>;
|
||||
}
|
||||
|
||||
/// Resource stock interfaces
|
||||
export interface BaseMappedResource<T> {
|
||||
@@ -448,7 +448,7 @@ declare namespace twilio {
|
||||
}
|
||||
|
||||
// For interop with node middleware chains
|
||||
export interface MiddlewareFunction { (request: Http.ServerRequest, response: Http.ServerResponse, next: Express.NextFunction): void; }
|
||||
export interface MiddlewareFunction { (request: Http.IncomingMessage, response: Http.ServerResponse, next: Express.NextFunction): void; }
|
||||
|
||||
export function webhook(authToken: string, options?: WebhookOptions): MiddlewareFunction;
|
||||
export function webhook(options?: WebhookOptions): MiddlewareFunction;
|
||||
@@ -581,7 +581,7 @@ declare namespace twilio {
|
||||
post: RestMethod;
|
||||
create: RestMethod;
|
||||
}
|
||||
export interface CallResource extends CreatableMappedResource<CallInstance> {
|
||||
export interface CallResource extends CreatableMappedResource<CallInstance>, ListableResource {
|
||||
feedbackSummary: CallFeedbackSummaryResource;
|
||||
}
|
||||
|
||||
|
||||
@@ -18,11 +18,16 @@ client.calls.get(function(err: any, response: any) {
|
||||
});
|
||||
});
|
||||
|
||||
// Using the alias described above
|
||||
client.calls.list(function(err: any, response: any) {
|
||||
response.calls.forEach(function(call: any) {});
|
||||
});
|
||||
|
||||
//Get a list of calls made by this account, from this phone number
|
||||
// GET /2010-04-01/Accounts/ACCOUNT_SID/Calls?From=+16513334455
|
||||
client.calls.get({
|
||||
from:'+16513334455'
|
||||
}, function(err: any, response: any) {
|
||||
}, function(err, response) {
|
||||
response.calls.forEach(function(call: any) {
|
||||
console.log('Received call from: ' + call.from);
|
||||
console.log('This call\'s unique ID is: ' + call.sid);
|
||||
@@ -31,14 +36,14 @@ client.calls.get({
|
||||
|
||||
//Get data for a specific call
|
||||
// GET /2010-04-01/Accounts/ACCOUNT_SID/Calls/abc123...
|
||||
client.calls('abc123...').get(function(err: any, call: any) {
|
||||
client.calls('abc123...').get(function(err, call) {
|
||||
console.log('This call\'s unique ID is: ' + call.sid);
|
||||
console.log('This call was created at: ' + call.dateCreated);
|
||||
});
|
||||
|
||||
//Get data for a specific call, for a specific account
|
||||
// GET /2010-04-01/Accounts/AC.../Calls/abc123...
|
||||
client.accounts('AC...').calls('abc123...').get(function(err: any, response: any) {
|
||||
client.accounts('AC...').calls('abc123...').get(function(err, response) {
|
||||
response.calls.forEach(function(call: any) {
|
||||
console.log('Received call from: ' + call.from);
|
||||
console.log('This call\'s unique ID is: ' + call.sid);
|
||||
@@ -59,7 +64,7 @@ client.sms.messages.post({
|
||||
|
||||
// Delete a TwiML application
|
||||
// DELETE /2010-04-01/Accounts/ACCOUNT_SID/Applications/APP...
|
||||
client.applications('APP...').delete(function(err: any, response: any, nodeResponse: any) {
|
||||
client.applications('APP...').delete(function(err, response, nodeResponse) {
|
||||
//DELETE requests do not return data - if there was no error, it worked.
|
||||
err ? console.log('There was an error') : console.log('it worked!');
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user