Skip to content

Commit

Permalink
Merge pull request #290 from jin60641/master
Browse files Browse the repository at this point in the history
add some typings for message api
  • Loading branch information
kellyjandrews authored Jul 23, 2020
2 parents 58b361c + 180d146 commit 0aeb3a2
Showing 1 changed file with 107 additions and 0 deletions.
107 changes: 107 additions & 0 deletions typings/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
/*
* TOOD: add prefix for Verify api's typings like Message api on next major update.
* RequestObject -> VerifyRequestObject
* RequestResponse -> VerifyRequestResponse
* RequestResponseStatusCode -> VerifyRequestResponseStatusCode
* ControlObject -> VerifyControlObject
* ControlResponse -> VerifyControlResponse
* ControlResponseStatusCode -> VerifyControlResponseStatusCode
* CheckObject -> VerifyCheckObject
* CheckResponse -> VerifyCheckResponse
*/

declare module 'nexmo' {
/* general */
export interface CredentialsObject {
Expand All @@ -19,6 +31,99 @@ declare module 'nexmo' {
parseError: Error;
}

/* message API */
export enum MessageRequestResponseStatusCode {
Success = '0',
Throttled = '1',
MissingParameters = '2',
InvalidParameters = '3',
InvalidCredentials = '4',
InternalError = '5',
InvalidMessage = '6',
NumberBarred = '7',
PartnerAccountBarred = '8',
PartnerQuotaViolation = '9',
TooManyExistingBinds = '10',
AccountNotEnabledForHTTP = '11',
MessageTooLong = '12',
InvalidSignature = '14',
InvalidSenderAddress = '15',
InvalidNetworkCode = '22',
InvalidCallbackURL = '23',
NonWhitelistedDestination = '29',
SignatureAndAPISecretDisallowed = '32',
NumberDeActivated = '33',
}

export interface MessageRequestResponseSuccess {
to: string,
'message-id': string,
status: MessageRequestResponseStatusCode,
'remaining-balance': string,
'message-price': string,
'network': string,
'account-ref': string,
}

export interface MessageError {
status: MessageRequestResponseStatusCode;
error_text: string;
}

export interface MessageRequestResponse {
'message-count': number;
messages: (MessageRequestResponseSuccess | MessageError)[];
}

export interface SendSmsOptions {
from: string;
to: string;
text?: string;
sig?: string;
ttl?: number;
'status-report-req'?: boolean;
callback?: string;
'message-class'?: number;
type?: string;
vcard?: string | any;
vcal?: string | any;
body?: string;
udh?: string;
'protocol-id'?: number;
title?: string;
url?: string;
validity?: string;
'client-ref'?: string;
'account-ref'?: string;
}

export type SendSms = (
sender: string,
recipient: string,
message: string,
opts: Partial<SendSmsOptions>,
callback: (err: MessageError, data: MessageRequestResponse) => void
) => void;

export class Message {
constructor(credentials: CredentialsObject, options: { [key: string]: any });
sendSms: SendSms;

/**
* TODO: typing
*/
sendBinaryMessage: any;
sendWapPushMessage: any;
shortcodeAlert: any;
shortcode2FA: any;
shortcodeMarketing: any;
search: any;
searchRejections: any;

__proto__: any;
[key: string]: any;
}

/* verify API */
export interface VerifyError extends NexmoApiError {
status: RequestResponseStatusCode | ControlResponseStatusCode | string;
Expand Down Expand Up @@ -100,9 +205,11 @@ declare module 'nexmo' {
[key: string]: any;
}


/* Nexmo */
export default class Nexmo {
constructor(credentials: CredentialsObject, options?: { [key: string]: any });
public readonly verify: Verify;
public readonly message: Message;
}
}

0 comments on commit 0aeb3a2

Please sign in to comment.