From 722d80281ef9633ce78a923c05b9d9ad2a6100dc Mon Sep 17 00:00:00 2001 From: Elmar Burke Date: Fri, 11 Jan 2019 13:40:00 +0100 Subject: [PATCH 1/7] add needed enviroment for typescript type definitions - Adds dtslint to test and lint the type definition files. - Sets the types property in package.json - adds npm-run script to run the linter --- package.json | 5 ++++- types/tsconfig.json | 22 ++++++++++++++++++++++ types/tslint.json | 7 +++++++ 3 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 types/tsconfig.json create mode 100644 types/tslint.json diff --git a/package.json b/package.json index 8a895fa..abc8e42 100644 --- a/package.json +++ b/package.json @@ -3,11 +3,13 @@ "version": "2.3.1", "description": "A node.js wrapper for the MessageBird REST API", "main": "lib/messagebird.js", + "types": "types", "engines": { "node": ">=0.8.0" }, "scripts": { - "test": "node lib/test.js" + "test": "node lib/test.js", + "dtslint": "dtslint types" }, "repository": { "type": "git", @@ -30,6 +32,7 @@ "homepage": "https://github.com/messagebird/messagebird-nodejs", "dependencies": {}, "devDependencies": { + "dtslint": "^0.4.2", "nock": "^8.0.0" } } diff --git a/types/tsconfig.json b/types/tsconfig.json new file mode 100644 index 0000000..da23847 --- /dev/null +++ b/types/tsconfig.json @@ -0,0 +1,22 @@ +{ + "compilerOptions": { + "target": "es5", + "module": "commonjs", + "lib": ["es5"], + "allowJs": false, + "checkJs": false, + "noEmit": true, + + "strict": true, + "noImplicitAny": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "strictBindCallApply": true, + "strictPropertyInitialization": true, + "noImplicitThis": true, + "alwaysStrict": true, + + "baseUrl": ".", + "paths": { "messagebird": ["."] } + } +} diff --git a/types/tslint.json b/types/tslint.json new file mode 100644 index 0000000..6bcb423 --- /dev/null +++ b/types/tslint.json @@ -0,0 +1,7 @@ +{ + "extends": "dtslint/dtslint.json", + "rules": { + // Use prettier for formating + "no-padding": false + } +} From 8d048ebbbc410a54d730b21128b537ffe51eb1d7 Mon Sep 17 00:00:00 2001 From: Elmar Burke Date: Mon, 14 Jan 2019 13:27:43 +0100 Subject: [PATCH 2/7] add typescript typings --- types/balance.d.ts | 16 ++++ types/contact.d.ts | 69 ++++++++++++++ types/general.d.ts | 3 + types/group.d.ts | 5 + types/hlr.d.ts | 49 ++++++++++ types/index.d.ts | 155 +++++++++++++++++++++++++++++++ types/lookup.d.ts | 53 +++++++++++ types/messages.d.ts | 126 ++++++++++++++++++++++++++ types/tests/balance.ts | 11 +++ types/tests/hlr.ts | 30 ++++++ types/tests/index.ts | 7 ++ types/tests/lookup.ts | 31 +++++++ types/tests/messages.ts | 24 +++++ types/tests/verify.ts | 42 +++++++++ types/tests/voice_messages.ts | 38 ++++++++ types/verify.d.ts | 70 ++++++++++++++ types/voice_messages.d.ts | 166 ++++++++++++++++++++++++++++++++++ 17 files changed, 895 insertions(+) create mode 100644 types/balance.d.ts create mode 100644 types/contact.d.ts create mode 100644 types/general.d.ts create mode 100644 types/group.d.ts create mode 100644 types/hlr.d.ts create mode 100644 types/index.d.ts create mode 100644 types/lookup.d.ts create mode 100644 types/messages.d.ts create mode 100644 types/tests/balance.ts create mode 100644 types/tests/hlr.ts create mode 100644 types/tests/index.ts create mode 100644 types/tests/lookup.ts create mode 100644 types/tests/messages.ts create mode 100644 types/tests/verify.ts create mode 100644 types/tests/voice_messages.ts create mode 100644 types/verify.d.ts create mode 100644 types/voice_messages.d.ts diff --git a/types/balance.d.ts b/types/balance.d.ts new file mode 100644 index 0000000..c956cdc --- /dev/null +++ b/types/balance.d.ts @@ -0,0 +1,16 @@ +/** + * payment type + * + * Possible values are: credits, euros, pounds & dollars. For all other supported currencies, an ISO-4217 code is returned + */ +export type PaymentType = 'credits' | 'euros' | 'pounds' | 'dollars' | string; + +export interface Balance { + /** payment method */ + payment: 'prepaid' | 'postpaid'; + + type: PaymentType; + + /** The amount of balance of the payment type. When postpaid is your payment method, the amount will be 0. */ + amount: number; +} diff --git a/types/contact.d.ts b/types/contact.d.ts new file mode 100644 index 0000000..2157f23 --- /dev/null +++ b/types/contact.d.ts @@ -0,0 +1,69 @@ +import { datetime } from 'general'; + +export interface Contact { + /** A unique random ID which is created on the MessageBird platform and is returned upon creation of the object. */ + id: string; + /** The URL of the created object. */ + href: string; + /** The phone number of contact. */ + msisdn: number; + /** The first name of the contact. */ + firstName: string; + /** The last name of the contact. */ + lastName: string; + /** Custom fields of the contact. */ + customDetails: CustomDetails; + + groups: Groups; + messages: Messages; + /** The date and time of the creation of the contact in RFC3339 format (Y-m-d\TH:i:sP). */ + createdDatetime: datetime; + /** The date and time of the last update of the contact in RFC3339 format (Y-m-d\TH:i:sP). */ + updatedDatetime: datetime; +} + +export interface CustomDetails { + /** Custom fields of the contact. */ + custom1: string; + /** Custom fields of the contact. */ + custom2: string; + /** Custom fields of the contact. */ + custom3: string; + /** Custom fields of the contact. */ + custom4: string; +} +export interface Groups { + /** The total count of groups that contact belongs to. */ + totalCount: number; + /** URL which can be used to retrieve list of groups contact belongs to. */ + href: string; +} +export interface Messages { + /** The total count of messages sent to contact. */ + totalCount: number; + /** URL which can be used to retrieve list of messages sent to contact. */ + href: string; +} + +export interface ContactParameter { + /** The phone number of the contact */ + msisdn: string; + + /** The first name of the contact. */ + firstName?: string; + + /** The last name of the contact. */ + lastName?: string; + + /** Custom fields of the contact. */ + custom1?: string; + + /** Custom fields of the contact. */ + custom2?: string; + + /** Custom fields of the contact. */ + custom3?: string; + + /** Custom fields of the contact. */ + custom4?: string; +} diff --git a/types/general.d.ts b/types/general.d.ts new file mode 100644 index 0000000..fc42a0c --- /dev/null +++ b/types/general.d.ts @@ -0,0 +1,3 @@ +/** The datum time in RFC3339 format (Y-m-d\TH:i:sP) */ +export type datetime = string; +export type msisdn = string | number; diff --git a/types/group.d.ts b/types/group.d.ts new file mode 100644 index 0000000..5a01116 --- /dev/null +++ b/types/group.d.ts @@ -0,0 +1,5 @@ +export interface GroupParameter { + + /** The name of the group. */ + name: string; +} diff --git a/types/hlr.d.ts b/types/hlr.d.ts new file mode 100644 index 0000000..95df973 --- /dev/null +++ b/types/hlr.d.ts @@ -0,0 +1,49 @@ +import { datetime } from './general'; + +export interface Hlr { + /** A unique random ID which is created on the MessageBird platform and is returned upon creation of the object. */ + id: string; + /** The URL of the created object. */ + href: string; + /** The telephone number. */ + msisdn: number; + /** The [MCCMNC](https://en.wikipedia.org/wiki/Mobile_country_code) code of the network provider. */ + network: number; + /** A client reference */ + reference: string; + /** A hash with extra HLR information. See table below for extra information. */ + details: Details; + /** The status of the msisdns. Possible values: sent, absent, active, unknown, and failed */ + status: string; + /** The date and time of the creation of the message in RFC3339 format (Y-m-d\TH:i:sP) */ + createdDatetime: datetime; + /** The datum time of the last status in RFC3339 format (Y-m-d\TH:i:sP) */ + statusDatetime: datetime; +} + +export interface Details { + /** Extended status information */ + status_desc?: string; + /** IMSI (International Mobile Subscriber Identity) of mobile number */ + imsi?: string; + /** Country ISO code of location of MSISDN */ + country_iso?: string; + /** Country name of location of MSISDN */ + country_name?: string; + /** MSC (Mobile Switching Center) of MSISDN */ + location_msc?: string; + /** Country ISO of MSC (lowercase ISO 3166-1 alpha-2) */ + location_iso?: string; + /** Is 1 if the phone number is ported or 0 when the phone number is not ported or ported status is unknown */ + ported?: 1 | 0; + /** Is 1 if the phone number is roaming or 0 when the phone number is not roaming or roaming status is unknown */ + roaming?: 1 | 0; +} + +export interface HLRParameter { + /** The telephone number that you want to do a network query on. */ + msisdn: number | string; + + /** A client reference. */ + reference?: string; +} diff --git a/types/index.d.ts b/types/index.d.ts new file mode 100644 index 0000000..b400f8c --- /dev/null +++ b/types/index.d.ts @@ -0,0 +1,155 @@ +// TypeScript Version: 3.0 + +import { Balance } from './balance'; +import { Hlr, HLRParameter } from './hlr'; +import { Message, MessageParameters } from 'messages'; +import { + VoiceMessage, + VoiceParameters, + VoiceParametersWithRecipients +} from 'voice_messages'; +import { msisdn } from 'general'; +import { Verify, VerifyParameter } from 'verify'; +import { Lookup } from 'lookup'; +import { Contact, ContactParameter } from 'contact'; +import { GroupParameter } from 'group'; + +declare namespace messagebird { + type CallbackFn = (err: Error | null, res: T | null) => void; + + interface MessageBird { + balance: { + /** Get account balance */ + read(callback: CallbackFn): void; + }; + hlr: { + read(id: string, callback: CallbackFn): void; + create(msisdn: msisdn, callback?: CallbackFn): void; + create(msisdn: msisdn, ref: string, callback: CallbackFn): void; + }; + messages: { + read(id: string, callback: CallbackFn): void; + create(params: MessageParameters, callback: CallbackFn): void; + }; + voice_messages: { + read(id: string, callback: CallbackFn): void; + create( + recipients: msisdn[], + params: VoiceParameters, + callback: CallbackFn + ): void; + create( + params: VoiceParametersWithRecipients, + callback: CallbackFn + ): void; + }; + verify: { + read(id: string, callback: CallbackFn): void; + create( + recipient: msisdn | [msisdn], + params: VerifyParameter, + callback: CallbackFn + ): void; + create(recipient: msisdn | [msisdn], callback: CallbackFn): void; + delete(id: string, callback: CallbackFn): void; + verify( + /** A unique random ID which is created on the MessageBird platform and is returned upon creation of the object. */ + id: string, + /** An unique token which was sent to the recipient upon creation of the object. */ + token: string, + callback: CallbackFn + ): void; + }; + lookup: { + read( + phoneNumber: msisdn, + countryCode: string, + callback: CallbackFn + ): void; + read(phoneNumber: msisdn, callback: CallbackFn): void; + hlr: { + read( + phoneNumber: msisdn, + countryCode: string, + callback: CallbackFn + ): void; + read(phoneNumber: msisdn, callback: CallbackFn): void; + create( + phoneNumber: msisdn, + params: HLRParameter, + callback: CallbackFn + ): void; + create(phoneNumber: msisdn, callback: CallbackFn): void; + }; + }; + contacts: { + create( + phoneNumber: string, + params: ContactParameter, + callback: CallbackFn + ): void; + create(phoneNumber: string, callback: CallbackFn): void; + delete(id: string, callback: CallbackFn): void; + list( + limit: number, + offset: number, + callback: CallbackFn + ): void; + list(callback: CallbackFn): void; + read(id: string, callback: CallbackFn): void; + update( + id: string, + params: ContactParameter, + callback: CallbackFn + ): void; + listGroups( + contactId: string, + limit: number, + offset: number, + callback: CallbackFn + ): void; + listGroups(contactId: string, callback: CallbackFn): void; + listMessages(contactId: string, callback: CallbackFn): void; + listMessages( + contactId: string, + limit: number, + offset: number, + callback: CallbackFn + ): void; + }; + groups: { + create(name: string, params: GroupParameter, callback: CallbackFn): void; + create(name: string, callback: CallbackFn): void; + delete(id: string, callback: CallbackFn): void; + list(limit: number, offset: number, callback: CallbackFn): void; + list(callback: CallbackFn): void; + read(id: string, callback: CallbackFn): void; + update(id: string, params: GroupParameter, callback: CallbackFn): void; + addContacts( + groupId: string, + contactIds: string[], + callback: CallbackFn + ): void; + getAddContactsQueryString(contactIds: string[]): string; + listContacts( + groupId: string, + limit: number, + offset: number, + callback: CallbackFn + ): void; + listContacts(groupId: string, callback: CallbackFn): void; + removeContact( + groupId: string, + contactId: string, + callback: CallbackFn + ): void; + }; + } +} + +declare function messagebird( + accessKey: string, + timeout?: number +): messagebird.MessageBird; + +export = messagebird; diff --git a/types/lookup.d.ts b/types/lookup.d.ts new file mode 100644 index 0000000..c2011ae --- /dev/null +++ b/types/lookup.d.ts @@ -0,0 +1,53 @@ +import { datetime } from 'general'; +import { Hlr } from 'hlr'; + +export type numberType = + | 'fixed line' + | 'mobile' + | 'fixed line or mobile' + | 'toll free' + | 'premium rate' + | 'shared cost' + | 'voip' + | 'personal number' + | 'pager' + | 'universal access number' + | 'voice mail' + | 'unknown'; + +export interface Lookup { + /** The URL of this lookup. */ + href: string; + + /** The country code for this number in ISO 3166-1 alpha-2 format. */ + countryCode: string; + + /** The country calling code for this number. */ + countryPrefix: number; + + /** The phone number in E.164 format without the prefixed plus-sign. */ + phoneNumber: number; + + /** The type of number. */ + type: numberType; + + /** A hash containing references to this phone number in several different formats. */ + formats: NumberFormat; + + /** The most recent HLR object. If no such HLR objects exists, this hash won't be returned. */ + hlr: Hlr; +} + +export interface NumberFormat { + /** The phone number in E.164 format. */ + e164: string; + + /** The phone number in international format. */ + international: string; + + /** The phone number in national/local format. */ + national: string; + + /** The phone number in RFC3966 format. */ + rfc3966: string; +} diff --git a/types/messages.d.ts b/types/messages.d.ts new file mode 100644 index 0000000..ccd383f --- /dev/null +++ b/types/messages.d.ts @@ -0,0 +1,126 @@ +import { datetime, msisdn } from 'general'; + +export type dataCoding = 'plain' | 'unicode' | 'auto'; +export type mclass = 0 | 1; +export type messageType = 'sms' | 'binary' | 'flash'; + +export interface Message { + /** A unique random ID which is created on the MessageBird platform and is returned upon creation of the object. */ + id: string; + /** The URL of the created object. */ + href: string; + /** + * Tells you if the message is sent or received. + * + * `mt`: mobile terminated (sent to mobile) + * + * `mo`: mobile originated (received from mobile) + */ + direction: 'mt' | 'mo'; + /** The type of message. */ + type: messageType; + /** + * The sender of the message. + * + * This can be a telephone number (including country code) or an alphanumeric string. + * In case of an alphanumeric string, the maximum length is 11 characters. + * You can set a default originator in your account or use inbox to use the Sticky VMN feature. + */ + originator: msisdn; + /** The body of the SMS message. */ + body: string; + /** A client reference. */ + reference: null; + /** The status report URL to be used on a per-message basis. `reference` is required for a status report webhook to be sent. */ + reportUrl: string; + /** The amount of seconds that the message is valid. If a message is not delivered within this time, the message will be discarded. */ + validity: number; + /** The SMS route that is used to send the message. */ + gateway: number; + typeDetails: TypeDetails; + /** The datacoding used, can be plain (GSM 03.38 characters only), unicode (contains non-GSM 03.38 characters) or auto, we will then set unicode or plain depending on the body content. */ + datacoding: dataCoding; + /** Indicated the message type. 1 is a normal message, 0 is a flash message. (0-3 are valid values) */ + mclass: mclass; + /** The scheduled date and time of the message in RFC3339 format (Y-m-d\TH:i:sP) */ + scheduledDatetime: datetime; + /** The date and time of the creation of the message in RFC3339 format (Y-m-d\TH:i:sP) */ + createdDatetime: datetime; + recipients: Recipients; +} + +export interface TypeDetails { + /** The [UDH](https://en.wikipedia.org/wiki/User_Data_Header) to prepend to the message payload. This can be used for sending concatenated SMS. Often required to send binary messages. */ + udh?: string; +} + +export interface Recipients { + /** The total count of recipients. */ + totalCount: number; + /** The count of recipients that have the message pending (status sent, and buffered). */ + totalSentCount: number; + /** The count of recipients where the message is delivered (status delivered). */ + totalDeliveredCount: number; + /** The count of recipients where the delivery has failed (status delivery_failed). */ + totalDeliveryFailedCount: number; + items: Recipient[]; +} + +export interface Recipient { + /** The msisdn of the recipient */ + recipient: number; + /** The status of the message sent to the recipient */ + status: + | 'scheduled' + | 'sent' + | 'buffered' + | 'delivered' + | 'expired' + | 'delivery_failed'; + /** The datum time of the last status in RFC3339 format (Y-m-d\TH:i:sP) */ + statusDatetime: datetime; +} + +export interface MessageParameters { + /** The sender of the message. This can be a telephone number (including country code) or an alphanumeric string. In case of an alphanumeric string, the maximum length is 11 characters. */ + originator: msisdn; + + /** The body of the SMS message. */ + body: string; + + /** The array of recipients msisdns. Note: can also contain groupIds. */ + recipients: msisdn[]; + + /** + * The type of message. Values can be: sms, binary, or flash. + */ + type?: messageType; + + /** A client reference. */ + reference?: string; + + /** The status report URL to be used on a per-message basis. reference is required for a status report webhook to be sent. */ + reportUrl?: string; + + /** The amount of seconds that the message is valid. If a message is not delivered within this time, the message will be discarded. */ + validity?: number; + + /** The SMS route that is used to send the message. */ + gateway?: number; + + /** An hash with extra information. Is only used when a binary message is sent. */ + typeDetails?: TypeDetails; + + /** + * Use plain when the body contains only GSM 03.38 characters, or you want non GSM 03.38 characters to be replaced. + * Use unicode to be able to send all characters. + * If you set auto, we will set unicode or plain depending on the body content. + */ + datacoding?: dataCoding; + + /** Indicated the message type. 1 is a normal message, 0 is a flash message. Default: 1 */ + mclass?: mclass; + + /** The scheduled date and time of the message in RFC3339 format (Y-m-d\TH:i:sP) */ + scheduledDatetime?: datetime; +} diff --git a/types/tests/balance.ts b/types/tests/balance.ts new file mode 100644 index 0000000..784bbaa --- /dev/null +++ b/types/tests/balance.ts @@ -0,0 +1,11 @@ +import * as messagebird from 'messagebird'; + +const mbClient = messagebird(''); + +mbClient.balance.read((err, balance) => { + // $ExpectType Error | null + err; + + // $ExpectType Balance | null + balance; +}); diff --git a/types/tests/hlr.ts b/types/tests/hlr.ts new file mode 100644 index 0000000..3097909 --- /dev/null +++ b/types/tests/hlr.ts @@ -0,0 +1,30 @@ +import * as messagebird from 'messagebird'; + +const mbClient = messagebird(''); + +// $ExpectType void +mbClient.hlr.read('', (err, hlr) => { + // $ExpectType Error | null + err; + + // ExpectType Hlr | null + hlr; +}); + +// $ExpectType void +mbClient.hlr.create(31612345678, (err, hlr) => { + // $ExpectType Error | null + err; + + // ExpectType Hlr | null + hlr; +}); + +// $ExpectType void +mbClient.hlr.create(31612345678, '', (err, hlr) => { + // $ExpectType Error | null + err; + + // ExpectType Hlr | null + hlr; +}); diff --git a/types/tests/index.ts b/types/tests/index.ts new file mode 100644 index 0000000..f26e293 --- /dev/null +++ b/types/tests/index.ts @@ -0,0 +1,7 @@ +import * as messagebird from 'messagebird'; + +// $ExpectType MessageBird +messagebird(''); + +// $ExpectType MessageBird +messagebird('', 42); diff --git a/types/tests/lookup.ts b/types/tests/lookup.ts new file mode 100644 index 0000000..2dd82da --- /dev/null +++ b/types/tests/lookup.ts @@ -0,0 +1,31 @@ +import * as messagebird from 'messagebird'; + +const mbClient = messagebird(''); + +mbClient.lookup.read('31612345678', ( + // $ExpectType Error | null + err, + // $ExpectType Lookup | null + lookupObject +) => {}); + +mbClient.lookup.read('0612345678', 'NL', ( + // $ExpectType Error | null + err, + // $ExpectType Lookup | null + lookupObject +) => {}); + +mbClient.lookup.hlr.read('31612345678', ( + // $ExpectType Error | null + err, + // $ExpectType Hlr | null + hlrObject +) => {}); + +mbClient.lookup.hlr.read('0612345678', 'NL', ( + // $ExpectType Error | null + err, + // $ExpectType Hlr | null + hlrObject +) => {}); diff --git a/types/tests/messages.ts b/types/tests/messages.ts new file mode 100644 index 0000000..926caf9 --- /dev/null +++ b/types/tests/messages.ts @@ -0,0 +1,24 @@ +import * as messagebird from 'messagebird'; + +const mbClient = messagebird(''); + +mbClient.messages.read('', ( + // $ExpectType Error | null + err, + // $ExpectType Message | null + message +) => {}); + +mbClient.messages.create( + { + originator: '', + recipients: [3161234567, '3161234567'], + body: '' + }, + ( + // $ExpectType Error | null + err, + // $ExpectType Message | null + message + ) => {} +); diff --git a/types/tests/verify.ts b/types/tests/verify.ts new file mode 100644 index 0000000..a507ad0 --- /dev/null +++ b/types/tests/verify.ts @@ -0,0 +1,42 @@ +import * as messagebird from 'messagebird'; + +const mbClient = messagebird(''); + +mbClient.verify.read('', ( + // $ExpectType Error | null + err, + // $ExpectType Verify | null + verifyObject +) => {}); + +mbClient.verify.create('31612345678', ( + // $ExpectType Error | null + err, + // $ExpectType Verify | null + verifyObject +) => {}); + +mbClient.verify.create('31612345678', { + type: "sms", + datacoding: "plain", + tokenLength: 8 +}, ( + // $ExpectType Error | null + err, + // $ExpectType Verify | null + verifyObject +) => {}); + +mbClient.verify.delete('', ( + // $ExpectType Error | null + err, + // $ExpectType void | null + verifyObject +) => {}); + +mbClient.verify.verify('', '', ( + // $ExpectType Error | null + err, + // $ExpectType Verify | null + verifyObject +) => {}); diff --git a/types/tests/voice_messages.ts b/types/tests/voice_messages.ts new file mode 100644 index 0000000..cd8cead --- /dev/null +++ b/types/tests/voice_messages.ts @@ -0,0 +1,38 @@ +import * as messagebird from 'messagebird'; + +const mbClient = messagebird(''); + +mbClient.voice_messages.read('', ( + // $ExpectType Error | null + err, + // $ExpectType VoiceMessage | null + voiceMessage +) => {}); + +mbClient.voice_messages.create( + { + originator: '', + recipients: [3161234567, '3161234567'], + body: '' + }, + ( + // $ExpectType Error | null + err, + // $ExpectType VoiceMessage | null + message + ) => {} +); + +mbClient.voice_messages.create( + [3161234567, '3161234567'], + { + originator: '', + body: '' + }, + ( + // $ExpectType Error | null + err, + // $ExpectType VoiceMessage | null + message + ) => {} +); diff --git a/types/verify.d.ts b/types/verify.d.ts new file mode 100644 index 0000000..46ff93e --- /dev/null +++ b/types/verify.d.ts @@ -0,0 +1,70 @@ +import { msisdn, datetime } from 'general'; +import { dataCoding } from 'messages'; +import { languages } from 'voice_messages'; + +export interface Verify { + /** A unique random ID which is created on the MessageBird platform and is returned upon creation of the object */ + id: string; + /** The URL of the created object. */ + href: string; + /** The msisdn of the recipient */ + recipient: msisdn; + /** A client reference */ + reference: string; + messages: { + /** The entry can either refer to either the messages or the voicemessages endpoint */ + href: string; + }; + /** The status of the verification. Possible values: sent, expired, failed, verified, and deleted */ + status: string; + /** The date and time of the creation of the Verify object in RFC3339 format (Y-m-d\TH:i:sP) */ + createdDatetime: datetime; + /** The date and time indicating the expiration time of the Verify object in RFC3339 format (Y-m-d\TH:i:sP) */ + validUntilDatetime: datetime; +} + +export interface VerifyParameter { + /** + * The sender of the message. This can be a telephone number (including country code) or an alphanumeric string. In case of an alphanumeric string, the maximum length is 11 characters. + * Default: Code + */ + originator?: string; + + /** A client reference. */ + reference?: string; + + /** + * The type of message. Values can be: sms, flash, tts + * Default: sms + */ + type?: 'sms' | 'flash' | 'tts'; + + /** + * The template of the message body. Needs to contain %token for the verification code to be included. + * Default: Your code is: %token + */ + template?: string; + + /** + * Use plain when the body contains only GSM 03.38 characters, or you want non GSM 03.38 characters to be replaced. Use unicode to be able to send all characters. + * If you set auto, we will set unicode or plain depending on the body content. + * Note: Using unicode will limit the maximum number of characters tot 70 instead of 160. + * If message character size exceeds the limit, messages will be concatenated, resulting in separately billed messages. + * Default: plain + */ + datacoding?: dataCoding; + + /** The verification code expiry time in seconds. Default: 30 */ + timeout?: number; + + /** The number of characters in the verification code. Must be between 6 and 10. Default: 6 */ + tokenLength?: number; + + /** The voice in which the messages needs to be read to the recipient. Possible values are: male, female. Default: female */ + voice?: 'female' | 'male'; + + /** + * The language in which the message needs to be read to the recipient. Default: en-gb + */ + language?: languages; +} diff --git a/types/voice_messages.d.ts b/types/voice_messages.d.ts new file mode 100644 index 0000000..fc8596a --- /dev/null +++ b/types/voice_messages.d.ts @@ -0,0 +1,166 @@ +import { datetime, msisdn } from 'general'; + +export type languages = + | 'cy-gb' + | 'da-dk' + | 'de-de' + | 'el-gr' + | 'en-au' + | 'en-gb' + | 'en-gb-wls' + | 'en-in' + | 'en-us' + | 'es-es' + | 'es-mx' + | 'es-us' + | 'fr-ca' + | 'fr-fr' + | 'id-id' + | 'is-is' + | 'it-it' + | 'ja-jp' + | 'ko-kr' + | 'ms-my' + | 'nb-no' + | 'nl-nl' + | 'pl-pl' + | 'pt-br' + | 'pt-pt' + | 'ro-ro' + | 'ru-ru' + | 'sv-se' + | 'ta-in' + | 'th-th' + | 'tr-tr' + | 'vi-vn' + | 'zh-cn' + | 'zh-hk'; +export type voice = 'female' | 'male'; + +export interface VoiceMessage { + /** A unique random ID which is created on the MessageBird platform and is returned upon creation of the object. */ + id: string; + + /** The URL of the created object. */ + href: string; + + /** A client reference */ + reference: string; + + /** The sender of the message. A telephone number (including country code). */ + originator: null; + + /** The body of the message. The maxlength is 1000 characters. */ + body: string; + + /** The language in which the message needs to be read to the recipient. */ + language: languages; + + /** The voice in which the messages needs to be read to the recipient. */ + voice: voice; + + /** The number of times the message needs to be repeated. Maximum is 10 times. */ + repeat: number; + + /** + * What to do when a machine picks up the phone? + * + * Possible values are: + * - `continue`: do not check, just play the message + * - `delay`: if a machine answers, wait until the machine stops talking + * - `hangup`: hangup when a machine answers + */ + ifMachine: 'continue' | 'delay' | 'hangup'; + + /** + * The time (in milliseconds) to analyze if a machine has picked up the phone. Used in combination with the delay and hangup values of the ifMachine attribute. + * + * Minimum: 400, maximum: 10000. + * + * Default is: 7000. + */ + machineTimeout: number; + /** The scheduled date and time of the message in RFC3339 format (Y-m-d\TH:i:sP) */ + scheduledDatetime: datetime; + /** The date and time of the creation of the message in RFC3339 format (Y-m-d\TH:i:sP) */ + createdDatetime: datetime; + recipients: Recipients; +} +export interface Recipients { + /** The total count of recipients. */ + totalCount: number; + /** The count of recipients that have the message pending (status "calling"). */ + totalSentCount: number; + /** The count of recipients where the message is delivered (status "answered"). */ + totalDeliveredCount: number; + /** The count of recipients where the delivery has failed (status "failed", "busy", "machine"). */ + totalDeliveryFailedCount: number; + items: Recipient[]; +} +export interface Recipient { + /** The msisdn of the recipient */ + recipient: number; + /** The status of the message sent to the recipient. Possible values: . For future use the following status are reserved: "busy" and "machine" */ + status: 'calling' | 'answered' | 'failed'; + /** The datum time of the last status in RFC3339 format (Y-m-d\TH:i:sP) */ + statusDatetime: datetime; +} + +export interface VoiceParameters { + /** The body of the SMS message. */ + body: string; + + /** The sender of the message. A telephone number (including country code). */ + originator?: string; + + /** A client reference. */ + reference?: string; + + /** + * The language in which the message needs to be read to the recipient. + * + * Default: en-gb + */ + language?: languages; + + /** + * The voice in which the messages needs to be read to the recipient. + * + * Default: female + */ + voice?: voice; + + /** + * The number of times the message needs to be repeated. + * + * Default: 1 + */ + repeat?: number; + + /** + * What to do when a machine picks up the phone? Possible values are: + * - continue do not check, just play the message + * - delay if a machine answers, wait until the machine stops talking + * - hangup hangup when a machine answers + * + * Default is: delay. + */ + ifMachine?: 'continue' | 'delay' | 'hangup'; + + /** + * The time (in milliseconds) to analyze if a machine has picked up the phone. Used in combination with the delay and hangup values of the ifMachine attribute. + * + * Minimum: 400, maximum: 10000. + * + * Default: 7000 + */ + machineTimeout?: number; + + /** The scheduled date and time of the message in RFC3339 format (Y-m-d\TH:i:sP) */ + scheduledDatetime?: Date; +} + +export interface VoiceParametersWithRecipients extends VoiceParameters { + /** The array of recipients msisdns. */ + recipients: msisdn[]; +} From a3c8ee5e7bbe222b57bc06f589094c4752f796ae Mon Sep 17 00:00:00 2001 From: Elmar Burke Date: Mon, 14 Jan 2019 13:31:55 +0100 Subject: [PATCH 3/7] add dtslint to travis runner --- .travis.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.travis.yml b/.travis.yml index de56ae6..2995bd4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,3 +17,8 @@ matrix: allow_failures: - node_js: "0.8" - node_js: "iojs" + +jobs: + include: + - stage: lint + script: npm run dtslint From 9e66f4a547e0613a82beeb49d1c4348862cab8ea Mon Sep 17 00:00:00 2001 From: Elmar Burke Date: Mon, 14 Jan 2019 13:37:38 +0100 Subject: [PATCH 4/7] remove unneeded namespace and export instance type --- types/index.d.ts | 245 ++++++++++++++++------------------ types/tests/balance.ts | 2 +- types/tests/hlr.ts | 2 +- types/tests/index.ts | 2 +- types/tests/lookup.ts | 2 +- types/tests/messages.ts | 2 +- types/tests/verify.ts | 2 +- types/tests/voice_messages.ts | 2 +- 8 files changed, 125 insertions(+), 134 deletions(-) diff --git a/types/index.d.ts b/types/index.d.ts index b400f8c..eeb4b95 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -14,142 +14,133 @@ import { Lookup } from 'lookup'; import { Contact, ContactParameter } from 'contact'; import { GroupParameter } from 'group'; -declare namespace messagebird { - type CallbackFn = (err: Error | null, res: T | null) => void; +type CallbackFn = (err: Error | null, res: T | null) => void; - interface MessageBird { - balance: { - /** Get account balance */ - read(callback: CallbackFn): void; - }; +export interface MessageBird { + balance: { + /** Get account balance */ + read(callback: CallbackFn): void; + }; + hlr: { + read(id: string, callback: CallbackFn): void; + create(msisdn: msisdn, callback?: CallbackFn): void; + create(msisdn: msisdn, ref: string, callback: CallbackFn): void; + }; + messages: { + read(id: string, callback: CallbackFn): void; + create(params: MessageParameters, callback: CallbackFn): void; + }; + voice_messages: { + read(id: string, callback: CallbackFn): void; + create( + recipients: msisdn[], + params: VoiceParameters, + callback: CallbackFn + ): void; + create( + params: VoiceParametersWithRecipients, + callback: CallbackFn + ): void; + }; + verify: { + read(id: string, callback: CallbackFn): void; + create( + recipient: msisdn | [msisdn], + params: VerifyParameter, + callback: CallbackFn + ): void; + create(recipient: msisdn | [msisdn], callback: CallbackFn): void; + delete(id: string, callback: CallbackFn): void; + verify( + /** A unique random ID which is created on the MessageBird platform and is returned upon creation of the object. */ + id: string, + /** An unique token which was sent to the recipient upon creation of the object. */ + token: string, + callback: CallbackFn + ): void; + }; + lookup: { + read( + phoneNumber: msisdn, + countryCode: string, + callback: CallbackFn + ): void; + read(phoneNumber: msisdn, callback: CallbackFn): void; hlr: { - read(id: string, callback: CallbackFn): void; - create(msisdn: msisdn, callback?: CallbackFn): void; - create(msisdn: msisdn, ref: string, callback: CallbackFn): void; - }; - messages: { - read(id: string, callback: CallbackFn): void; - create(params: MessageParameters, callback: CallbackFn): void; - }; - voice_messages: { - read(id: string, callback: CallbackFn): void; - create( - recipients: msisdn[], - params: VoiceParameters, - callback: CallbackFn - ): void; - create( - params: VoiceParametersWithRecipients, - callback: CallbackFn - ): void; - }; - verify: { - read(id: string, callback: CallbackFn): void; - create( - recipient: msisdn | [msisdn], - params: VerifyParameter, - callback: CallbackFn - ): void; - create(recipient: msisdn | [msisdn], callback: CallbackFn): void; - delete(id: string, callback: CallbackFn): void; - verify( - /** A unique random ID which is created on the MessageBird platform and is returned upon creation of the object. */ - id: string, - /** An unique token which was sent to the recipient upon creation of the object. */ - token: string, - callback: CallbackFn - ): void; - }; - lookup: { read( phoneNumber: msisdn, countryCode: string, - callback: CallbackFn + callback: CallbackFn ): void; - read(phoneNumber: msisdn, callback: CallbackFn): void; - hlr: { - read( - phoneNumber: msisdn, - countryCode: string, - callback: CallbackFn - ): void; - read(phoneNumber: msisdn, callback: CallbackFn): void; - create( - phoneNumber: msisdn, - params: HLRParameter, - callback: CallbackFn - ): void; - create(phoneNumber: msisdn, callback: CallbackFn): void; - }; - }; - contacts: { + read(phoneNumber: msisdn, callback: CallbackFn): void; create( - phoneNumber: string, - params: ContactParameter, - callback: CallbackFn - ): void; - create(phoneNumber: string, callback: CallbackFn): void; - delete(id: string, callback: CallbackFn): void; - list( - limit: number, - offset: number, - callback: CallbackFn - ): void; - list(callback: CallbackFn): void; - read(id: string, callback: CallbackFn): void; - update( - id: string, - params: ContactParameter, - callback: CallbackFn - ): void; - listGroups( - contactId: string, - limit: number, - offset: number, - callback: CallbackFn - ): void; - listGroups(contactId: string, callback: CallbackFn): void; - listMessages(contactId: string, callback: CallbackFn): void; - listMessages( - contactId: string, - limit: number, - offset: number, - callback: CallbackFn - ): void; - }; - groups: { - create(name: string, params: GroupParameter, callback: CallbackFn): void; - create(name: string, callback: CallbackFn): void; - delete(id: string, callback: CallbackFn): void; - list(limit: number, offset: number, callback: CallbackFn): void; - list(callback: CallbackFn): void; - read(id: string, callback: CallbackFn): void; - update(id: string, params: GroupParameter, callback: CallbackFn): void; - addContacts( - groupId: string, - contactIds: string[], - callback: CallbackFn - ): void; - getAddContactsQueryString(contactIds: string[]): string; - listContacts( - groupId: string, - limit: number, - offset: number, - callback: CallbackFn - ): void; - listContacts(groupId: string, callback: CallbackFn): void; - removeContact( - groupId: string, - contactId: string, - callback: CallbackFn + phoneNumber: msisdn, + params: HLRParameter, + callback: CallbackFn ): void; + create(phoneNumber: msisdn, callback: CallbackFn): void; }; - } + }; + contacts: { + create( + phoneNumber: string, + params: ContactParameter, + callback: CallbackFn + ): void; + create(phoneNumber: string, callback: CallbackFn): void; + delete(id: string, callback: CallbackFn): void; + list(limit: number, offset: number, callback: CallbackFn): void; + list(callback: CallbackFn): void; + read(id: string, callback: CallbackFn): void; + update( + id: string, + params: ContactParameter, + callback: CallbackFn + ): void; + listGroups( + contactId: string, + limit: number, + offset: number, + callback: CallbackFn + ): void; + listGroups(contactId: string, callback: CallbackFn): void; + listMessages(contactId: string, callback: CallbackFn): void; + listMessages( + contactId: string, + limit: number, + offset: number, + callback: CallbackFn + ): void; + }; + groups: { + create(name: string, params: GroupParameter, callback: CallbackFn): void; + create(name: string, callback: CallbackFn): void; + delete(id: string, callback: CallbackFn): void; + list(limit: number, offset: number, callback: CallbackFn): void; + list(callback: CallbackFn): void; + read(id: string, callback: CallbackFn): void; + update(id: string, params: GroupParameter, callback: CallbackFn): void; + addContacts( + groupId: string, + contactIds: string[], + callback: CallbackFn + ): void; + getAddContactsQueryString(contactIds: string[]): string; + listContacts( + groupId: string, + limit: number, + offset: number, + callback: CallbackFn + ): void; + listContacts(groupId: string, callback: CallbackFn): void; + removeContact( + groupId: string, + contactId: string, + callback: CallbackFn + ): void; + }; } -declare function messagebird( - accessKey: string, - timeout?: number -): messagebird.MessageBird; +declare function messagebird(accessKey: string, timeout?: number): MessageBird; -export = messagebird; +export default messagebird; diff --git a/types/tests/balance.ts b/types/tests/balance.ts index 784bbaa..7f78127 100644 --- a/types/tests/balance.ts +++ b/types/tests/balance.ts @@ -1,4 +1,4 @@ -import * as messagebird from 'messagebird'; +import messagebird from 'messagebird'; const mbClient = messagebird(''); diff --git a/types/tests/hlr.ts b/types/tests/hlr.ts index 3097909..8feb2b0 100644 --- a/types/tests/hlr.ts +++ b/types/tests/hlr.ts @@ -1,4 +1,4 @@ -import * as messagebird from 'messagebird'; +import messagebird from 'messagebird'; const mbClient = messagebird(''); diff --git a/types/tests/index.ts b/types/tests/index.ts index f26e293..dd66562 100644 --- a/types/tests/index.ts +++ b/types/tests/index.ts @@ -1,4 +1,4 @@ -import * as messagebird from 'messagebird'; +import messagebird from 'messagebird'; // $ExpectType MessageBird messagebird(''); diff --git a/types/tests/lookup.ts b/types/tests/lookup.ts index 2dd82da..234cf21 100644 --- a/types/tests/lookup.ts +++ b/types/tests/lookup.ts @@ -1,4 +1,4 @@ -import * as messagebird from 'messagebird'; +import messagebird from 'messagebird'; const mbClient = messagebird(''); diff --git a/types/tests/messages.ts b/types/tests/messages.ts index 926caf9..c844ef3 100644 --- a/types/tests/messages.ts +++ b/types/tests/messages.ts @@ -1,4 +1,4 @@ -import * as messagebird from 'messagebird'; +import messagebird from 'messagebird'; const mbClient = messagebird(''); diff --git a/types/tests/verify.ts b/types/tests/verify.ts index a507ad0..9e51d83 100644 --- a/types/tests/verify.ts +++ b/types/tests/verify.ts @@ -1,4 +1,4 @@ -import * as messagebird from 'messagebird'; +import messagebird from 'messagebird'; const mbClient = messagebird(''); diff --git a/types/tests/voice_messages.ts b/types/tests/voice_messages.ts index cd8cead..581a2d9 100644 --- a/types/tests/voice_messages.ts +++ b/types/tests/voice_messages.ts @@ -1,4 +1,4 @@ -import * as messagebird from 'messagebird'; +import messagebird from 'messagebird'; const mbClient = messagebird(''); From 77c892c6b495ba7fab2fd7b571b093c23b0ae594 Mon Sep 17 00:00:00 2001 From: Elmar Burke Date: Fri, 25 Jan 2019 15:49:44 +0100 Subject: [PATCH 5/7] add conversation typing --- package-lock.json | 403 +++++++++++++++++++++++++++++++++++++++ types/conversations.d.ts | 159 +++++++++++++++ types/index.d.ts | 107 ++++++++++- 3 files changed, 662 insertions(+), 7 deletions(-) create mode 100644 types/conversations.d.ts diff --git a/package-lock.json b/package-lock.json index 1e3455f..2c7a919 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4,12 +4,87 @@ "lockfileVersion": 1, "requires": true, "dependencies": { + "@types/parsimmon": { + "version": "1.10.0", + "resolved": "https://registry.npmjs.org/@types/parsimmon/-/parsimmon-1.10.0.tgz", + "integrity": "sha512-bsTIJFVQv7jnvNiC42ld2pQW2KRI+pAG243L+iATvqzy3X6+NH1obz2itRKDZZ8VVhN3wjwYax/VBGCcXzgTqQ==", + "dev": true + }, + "ansi-regex": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.1.1.tgz", + "integrity": "sha1-w7M6te42DYbg5ijwRorn7yfWVN8=", + "dev": true + }, + "ansi-styles": { + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-2.2.1.tgz", + "integrity": "sha1-tDLdM1i2NM914eRmQ2gkBTPB3b4=", + "dev": true + }, + "argparse": { + "version": "1.0.10", + "resolved": "https://registry.npmjs.org/argparse/-/argparse-1.0.10.tgz", + "integrity": "sha512-o5Roy6tNG4SL/FOkCAN6RzjiakZS25RLYFrcMttJqbdd8BWrnA+fGz57iN5Pb06pvBGvl5gQ0B48dJlslXvoTg==", + "dev": true, + "requires": { + "sprintf-js": "~1.0.2" + } + }, "assertion-error": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/assertion-error/-/assertion-error-1.1.0.tgz", "integrity": "sha512-jgsaNduz+ndvGyFt3uSuWqvy4lCnIJiovtouQN5JZHOKCS2QuhEdbcQHFhVksz2N2U9hXJo8odG7ETyWlEeuDw==", "dev": true }, + "babel-code-frame": { + "version": "6.26.0", + "resolved": "https://registry.npmjs.org/babel-code-frame/-/babel-code-frame-6.26.0.tgz", + "integrity": "sha1-Y/1D99weO7fONZR9uP42mj9Yx0s=", + "dev": true, + "requires": { + "chalk": "^1.1.3", + "esutils": "^2.0.2", + "js-tokens": "^3.0.2" + }, + "dependencies": { + "chalk": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-1.1.3.tgz", + "integrity": "sha1-qBFcVeSnAv5NFQq9OHKCKn4J/Jg=", + "dev": true, + "requires": { + "ansi-styles": "^2.2.1", + "escape-string-regexp": "^1.0.2", + "has-ansi": "^2.0.0", + "strip-ansi": "^3.0.0", + "supports-color": "^2.0.0" + } + } + } + }, + "balanced-match": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", + "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=", + "dev": true + }, + "brace-expansion": { + "version": "1.1.11", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", + "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", + "dev": true, + "requires": { + "balanced-match": "^1.0.0", + "concat-map": "0.0.1" + } + }, + "builtin-modules": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/builtin-modules/-/builtin-modules-1.1.1.tgz", + "integrity": "sha1-Jw8HbFpywC9bZaR9+Uxf46J4iS8=", + "dev": true + }, "chai": { "version": "3.5.0", "resolved": "https://registry.npmjs.org/chai/-/chai-3.5.0.tgz", @@ -21,6 +96,64 @@ "type-detect": "^1.0.0" } }, + "chalk": { + "version": "2.4.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz", + "integrity": "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==", + "dev": true, + "requires": { + "ansi-styles": "^3.2.1", + "escape-string-regexp": "^1.0.5", + "supports-color": "^5.3.0" + }, + "dependencies": { + "ansi-styles": { + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz", + "integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==", + "dev": true, + "requires": { + "color-convert": "^1.9.0" + } + }, + "supports-color": { + "version": "5.5.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz", + "integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==", + "dev": true, + "requires": { + "has-flag": "^3.0.0" + } + } + } + }, + "color-convert": { + "version": "1.9.3", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz", + "integrity": "sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==", + "dev": true, + "requires": { + "color-name": "1.1.3" + } + }, + "color-name": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", + "integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=", + "dev": true + }, + "commander": { + "version": "2.19.0", + "resolved": "https://registry.npmjs.org/commander/-/commander-2.19.0.tgz", + "integrity": "sha512-6tvAOO+D6OENvRAh524Dh9jcfKTYDQAqvqezbCW82xj5X0pSrcpxtvRKHLG0yBY6SD7PSDrJaj+0AiOcKVd1Xg==", + "dev": true + }, + "concat-map": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", + "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=", + "dev": true + }, "debug": { "version": "2.6.9", "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", @@ -53,18 +186,166 @@ "integrity": "sha1-9dJgKStmDghO/0zbyfCK0yR0SLU=", "dev": true }, + "definitelytyped-header-parser": { + "version": "github:Microsoft/definitelytyped-header-parser#e0561530379dfa01324a89936b75d90b20df9bd2", + "from": "github:Microsoft/definitelytyped-header-parser#production", + "dev": true, + "requires": { + "@types/parsimmon": "^1.3.0", + "parsimmon": "^1.2.0" + } + }, + "diff": { + "version": "3.5.0", + "resolved": "https://registry.npmjs.org/diff/-/diff-3.5.0.tgz", + "integrity": "sha512-A46qtFgd+g7pDZinpnwiRJtxbC1hpgf0uzP3iG89scHk0AUC7A1TGxf5OiiOUv/JMZR8GOt8hL900hV0bOy5xA==", + "dev": true + }, + "dtslint": { + "version": "0.4.2", + "resolved": "https://registry.npmjs.org/dtslint/-/dtslint-0.4.2.tgz", + "integrity": "sha512-ph4GXLw3HYzlQMJOFcpCqWHuL3MxJ/344OR7wn0wlQGchQGTIVNsSUl8iKEMatpy2geNMysgA9fQa6xVhHOkTQ==", + "dev": true, + "requires": { + "definitelytyped-header-parser": "github:Microsoft/definitelytyped-header-parser#e0561530379dfa01324a89936b75d90b20df9bd2", + "fs-extra": "^6.0.1", + "strip-json-comments": "^2.0.1", + "tslint": "^5.12.0", + "typescript": "^3.3.0-dev.20190126" + } + }, + "escape-string-regexp": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", + "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=", + "dev": true + }, + "esprima": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/esprima/-/esprima-4.0.1.tgz", + "integrity": "sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A==", + "dev": true + }, + "esutils": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/esutils/-/esutils-2.0.2.tgz", + "integrity": "sha1-Cr9PHKpbyx96nYrMbepPqqBLrJs=", + "dev": true + }, + "fs-extra": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-6.0.1.tgz", + "integrity": "sha512-GnyIkKhhzXZUWFCaJzvyDLEEgDkPfb4/TPvJCJVuS8MWZgoSsErf++QpiAlDnKFcqhRlm+tIOcencCjyJE6ZCA==", + "dev": true, + "requires": { + "graceful-fs": "^4.1.2", + "jsonfile": "^4.0.0", + "universalify": "^0.1.0" + } + }, + "fs.realpath": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", + "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=", + "dev": true + }, + "glob": { + "version": "7.1.3", + "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.3.tgz", + "integrity": "sha512-vcfuiIxogLV4DlGBHIUOwI0IbrJ8HWPc4MU7HzviGeNho/UJDfi6B5p3sHeWIQ0KGIU0Jpxi5ZHxemQfLkkAwQ==", + "dev": true, + "requires": { + "fs.realpath": "^1.0.0", + "inflight": "^1.0.4", + "inherits": "2", + "minimatch": "^3.0.4", + "once": "^1.3.0", + "path-is-absolute": "^1.0.0" + } + }, + "graceful-fs": { + "version": "4.1.15", + "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.1.15.tgz", + "integrity": "sha512-6uHUhOPEBgQ24HM+r6b/QwWfZq+yiFcipKFrOFiBEnWdy5sdzYoi+pJeQaPI5qOLRFqWmAXUPQNsielzdLoecA==", + "dev": true + }, + "has-ansi": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/has-ansi/-/has-ansi-2.0.0.tgz", + "integrity": "sha1-NPUEnOHs3ysGSa8+8k5F7TVBbZE=", + "dev": true, + "requires": { + "ansi-regex": "^2.0.0" + } + }, + "has-flag": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", + "integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0=", + "dev": true + }, + "inflight": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", + "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=", + "dev": true, + "requires": { + "once": "^1.3.0", + "wrappy": "1" + } + }, + "inherits": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", + "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=", + "dev": true + }, + "js-tokens": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-3.0.2.tgz", + "integrity": "sha1-mGbfOVECEw449/mWvOtlRDIJwls=", + "dev": true + }, + "js-yaml": { + "version": "3.12.1", + "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.12.1.tgz", + "integrity": "sha512-um46hB9wNOKlwkHgiuyEVAybXBjwFUV0Z/RaHJblRd9DXltue9FTYvzCr9ErQrK9Adz5MU4gHWVaNUfdmrC8qA==", + "dev": true, + "requires": { + "argparse": "^1.0.7", + "esprima": "^4.0.0" + } + }, "json-stringify-safe": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/json-stringify-safe/-/json-stringify-safe-5.0.1.tgz", "integrity": "sha1-Epai1Y/UXxmg9s4B1lcB4sc1tus=", "dev": true }, + "jsonfile": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-4.0.0.tgz", + "integrity": "sha1-h3Gq4HmbZAdrdmQPygWPnBDjPss=", + "dev": true, + "requires": { + "graceful-fs": "^4.1.6" + } + }, "lodash": { "version": "4.9.0", "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.9.0.tgz", "integrity": "sha1-TCDXQvA86F3HAODderm8q4Xm/BQ=", "dev": true }, + "minimatch": { + "version": "3.0.4", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", + "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", + "dev": true, + "requires": { + "brace-expansion": "^1.1.7" + } + }, "minimist": { "version": "0.0.8", "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz", @@ -102,6 +383,33 @@ "qs": "^6.0.2" } }, + "once": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", + "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", + "dev": true, + "requires": { + "wrappy": "1" + } + }, + "parsimmon": { + "version": "1.12.0", + "resolved": "https://registry.npmjs.org/parsimmon/-/parsimmon-1.12.0.tgz", + "integrity": "sha512-uC/BjuSfb4jfaWajKCp1mVncXXq+V1twbcYChbTxN3GM7fn+8XoHwUdvUz+PTaFtDSCRQxU8+Rnh+iMhAkVwdw==", + "dev": true + }, + "path-is-absolute": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", + "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=", + "dev": true + }, + "path-parse": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.6.tgz", + "integrity": "sha512-GSmOT2EbHrINBf9SR7CDELwlJ8AENk3Qn7OikK4nFYAu3Ote2+JYNVvkpAEQm3/TLNEJFD/xZJjzyxg3KBWOzw==", + "dev": true + }, "propagate": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/propagate/-/propagate-0.4.0.tgz", @@ -114,11 +422,106 @@ "integrity": "sha512-KIJqT9jQJDQx5h5uAVPimw6yVg2SekOKu959OCtktD3FjzbpvaPr8i4zzg07DOMz+igA4W/aNM7OV8H37pFYfA==", "dev": true }, + "resolve": { + "version": "1.10.0", + "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.10.0.tgz", + "integrity": "sha512-3sUr9aq5OfSg2S9pNtPA9hL1FVEAjvfOC4leW0SNf/mpnaakz2a9femSd6LqAww2RaFctwyf1lCqnTHuF1rxDg==", + "dev": true, + "requires": { + "path-parse": "^1.0.6" + } + }, + "semver": { + "version": "5.6.0", + "resolved": "https://registry.npmjs.org/semver/-/semver-5.6.0.tgz", + "integrity": "sha512-RS9R6R35NYgQn++fkDWaOmqGoj4Ek9gGs+DPxNUZKuwE183xjJroKvyo1IzVFeXvUrvmALy6FWD5xrdJT25gMg==", + "dev": true + }, + "sprintf-js": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz", + "integrity": "sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw=", + "dev": true + }, + "strip-ansi": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz", + "integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=", + "dev": true, + "requires": { + "ansi-regex": "^2.0.0" + } + }, + "strip-json-comments": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-2.0.1.tgz", + "integrity": "sha1-PFMZQukIwml8DsNEhYwobHygpgo=", + "dev": true + }, + "supports-color": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-2.0.0.tgz", + "integrity": "sha1-U10EXOa2Nj+kARcIRimZXp3zJMc=", + "dev": true + }, + "tslib": { + "version": "1.9.3", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.9.3.tgz", + "integrity": "sha512-4krF8scpejhaOgqzBEcGM7yDIEfi0/8+8zDRZhNZZ2kjmHJ4hv3zCbQWxoJGz1iw5U0Jl0nma13xzHXcncMavQ==", + "dev": true + }, + "tslint": { + "version": "5.12.1", + "resolved": "https://registry.npmjs.org/tslint/-/tslint-5.12.1.tgz", + "integrity": "sha512-sfodBHOucFg6egff8d1BvuofoOQ/nOeYNfbp7LDlKBcLNrL3lmS5zoiDGyOMdT7YsEXAwWpTdAHwOGOc8eRZAw==", + "dev": true, + "requires": { + "babel-code-frame": "^6.22.0", + "builtin-modules": "^1.1.1", + "chalk": "^2.3.0", + "commander": "^2.12.1", + "diff": "^3.2.0", + "glob": "^7.1.1", + "js-yaml": "^3.7.0", + "minimatch": "^3.0.4", + "resolve": "^1.3.2", + "semver": "^5.3.0", + "tslib": "^1.8.0", + "tsutils": "^2.27.2" + } + }, + "tsutils": { + "version": "2.29.0", + "resolved": "https://registry.npmjs.org/tsutils/-/tsutils-2.29.0.tgz", + "integrity": "sha512-g5JVHCIJwzfISaXpXE1qvNalca5Jwob6FjI4AoPlqMusJ6ftFE7IkkFoMhVLRgK+4Kx3gkzb8UZK5t5yTTvEmA==", + "dev": true, + "requires": { + "tslib": "^1.8.1" + } + }, "type-detect": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/type-detect/-/type-detect-1.0.0.tgz", "integrity": "sha1-diIXzAbbJY7EiQihKY6LlRIejqI=", "dev": true + }, + "typescript": { + "version": "3.3.0-dev.20190126", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.3.0-dev.20190126.tgz", + "integrity": "sha512-wx5ZIi0Dn61N/H+TDLQIyG+DPvtk46t/lHeKmu2jwk5sW7GIPjVRPUJ5AR9ohdSkV0pEUshZolWSABz5f1pTAA==", + "dev": true + }, + "universalify": { + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/universalify/-/universalify-0.1.2.tgz", + "integrity": "sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg==", + "dev": true + }, + "wrappy": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", + "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=", + "dev": true } } } diff --git a/types/conversations.d.ts b/types/conversations.d.ts new file mode 100644 index 0000000..fcfb42c --- /dev/null +++ b/types/conversations.d.ts @@ -0,0 +1,159 @@ +import { Language } from 'parsimmon'; +import { datetime } from 'general'; + +export interface StartConversationParameter { + /** The type of the message content. */ + type: string; + /** Content of the message to send. The value of type defines the required fields. */ + content: Content; + /** An channel-specific identifier for the receiver. For example: a mobile phone number (MSISDN) is valid for SMS or Whatsapp channels. */ + to?: string; + /** The unique ID that identifies the channel over which the message should be sent. */ + channelId?: string; +} + +export interface ConversationParameter { + /** Either a channel-specific identifier for the receiver (e.g. MSISDN for SMS or WhatsApp channels), or the ID of a MessageBird Contact. */ + to: string; + + /** The ID that identifies the channel over which the message should be sent. */ + from: string; + + /** The type of the message content. */ + type: string; + + /** Content of the message. The value of type defines the required fields. */ + content: Content; + + /** The URL for delivery of status reports for the message. Must be HTTPS. */ + reportUrl: string; +} + +export type Content = + | TextContent + | ImageContent + | AudioContent + | FileContent + | LocationContent + | HSMContent; + +export interface TextContent { + /** Required for type text. The plain-text content of the message. */ + text: string; +} + +export interface ImageContent { + /** Required for type image. An object of the form {"url": ""} containing the url of the remote media file. */ + image: object; +} + +export interface AudioContent { + /** Required for type video. An object of the form {"url": ""} containing the url of the remote media file. */ + video: object; +} + +export interface FileContent { + /** Required for type file. An object of the form {"url": ""} containing the url of the remote media file. */ + file: object; +} + +export interface LocationContent { + /** Latitude and longitude are expected as floats. */ + location: { + latitude: number; + longitude: number; + }; +} + +export interface HSMContent { + /** Required for type hsm. Available only for WhatsApp. */ + hsm: HSMContentContent; +} + +export interface HSMContentContent { + /** WhatsApp namespace for your account. You will receive this value when setting up your WhatsApp account. */ + namespace: string; + + /** The name of the template. */ + templateName: string; + language: HSMLanguage; + params: HSMLocalizableParameters[]; +} + +export interface HSMLanguage { + /** + * Deterministic will deliver the message template in exactly the language and locale asked for while fallback will deliver the message template in user's device language, + * if the settings can't be found on users device the fallback language is used. + */ + policy: 'fallback' | 'deterministic'; + /** The code of the language or locale to use, accepts both language and language_locale formats (e.g., en or en_US). */ + code: Language; +} + +export type HSMLocalizableParameters = + | HSMLocalizableParametersCurrency + | HSMLocalizableParametersDateTime; + +export interface HSMLocalizableParametersCurrency { + /** + * Default value of the parameter, it is used when localization fails. The only field needed when specifying parameter value that doesn't require localization. + */ + default: string; + currency?: { + /** string of ISO 4217 currency code */ + currencyCode: string; + /** integer of total amount together with cents as a float, multipled by 1000 */ + amount: number; + }; +} + +export interface HSMLocalizableParametersDateTime { + /** + * Default value of the parameter, it is used when localization fails. The only field needed when specifying parameter value that doesn't require localization. + */ + default: string; + /** + * RFC3339 representation of the date and time. + */ + dateTime?: datetime; +} + +export interface SendResponse { + message: Message; +} + +export interface Message { + /** A unique ID generated by the MessageBird platform that identifies this message. */ + id: string; + /** The status of the message. It will be initially set to accepted. */ + status: string | 'accepted'; +} + +export interface UpdateConversationParameters { + /** The new status of the conversation */ + status: 'active' | 'archived'; +} + +export interface ReplyConversationParameters { + /** The unique ID that identifies the conversation */ + id: string; +} + +export namespace Webhooks { + interface CreateParameters { + /** A list of event name strings from the list of available events that should trigger this webhook. */ + events: string[]; + /** The unique identifier for a MessageBird channel that this webhook will subcribe to events for. */ + channelId: string; + /** The endpoint URL that requests should be sent to. */ + url: string; + } + interface UpdateParameters { + /** A list of event name strings from the list of available events that should trigger this webhook. */ + events: string[]; + /** The endpoint URL that requests should be sent to. */ + url: string; + /** Status of the webhook */ + status: 'enabled' | 'disabled'; + } +} diff --git a/types/index.d.ts b/types/index.d.ts index eeb4b95..19e21b3 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -2,17 +2,24 @@ import { Balance } from './balance'; import { Hlr, HLRParameter } from './hlr'; -import { Message, MessageParameters } from 'messages'; +import { Message, MessageParameters } from './messages'; import { VoiceMessage, VoiceParameters, VoiceParametersWithRecipients -} from 'voice_messages'; -import { msisdn } from 'general'; -import { Verify, VerifyParameter } from 'verify'; -import { Lookup } from 'lookup'; -import { Contact, ContactParameter } from 'contact'; -import { GroupParameter } from 'group'; +} from './voice_messages'; +import { msisdn } from './general'; +import { Verify, VerifyParameter } from './verify'; +import { Lookup } from './lookup'; +import { Contact, ContactParameter } from './contact'; +import { GroupParameter } from './group'; +import { + ConversationParameter, + SendResponse, + UpdateConversationParameters, + ReplyConversationParameters, + Webhooks +} from './conversations'; type CallbackFn = (err: Error | null, res: T | null) => void; @@ -139,6 +146,92 @@ export interface MessageBird { callback: CallbackFn ): void; }; + conversations: { + /** + * Sends a new message to a channel-specific user identifier (e.g. phone + * number). If an active conversation already exists for the recipient, + * this conversation will be resumed. If an active conversation does not + * exist, a new one will be created. + */ + send( + params: ConversationParameter, + callback: CallbackFn + ): void; + /** + * Starts a new conversation from a channel-specific user identifier, + * such as a phone number, and sends a first message. If an active + * conversation already exists for the recipient, this conversation will + * be resumed. + */ + start(params: ConversationParameter, callback: CallbackFn): void; + /** + * Retrieves all conversations for this account. By default, + * conversations are sorted by their lastReceivedDatetime field so that + * conversations with new messages appear first. + */ + list(limit: number, offset: number, callback: CallbackFn): void; + /** + * Retrieves a single conversation. + */ + read(id: string, callback: CallbackFn): void; + /** + * Update Conversation Status. + */ + update( + id: string, + params: UpdateConversationParameters, + callback: CallbackFn + ): void; + /** + * Adds a new message to an existing conversation and sends it to the + * contact that you're in conversation with. + */ + reply( + id: string, + params: ReplyConversationParameters, + callback: CallbackFn + ): void; + /** + * Lists the messages for a contact. + */ + listMessages( + contactId: string, + limit: number, + offset: number, + callback: CallbackFn + ): void; + /** + * View a message + */ + readMessage(id: string, callback: CallbackFn): void; + + webhooks: { + /** + * Creates a new webhook. + */ + create(params: Webhooks.CreateParameters, callback: CallbackFn): void; + /** + * Retrieves an existing webhook by id. + */ + read(id: string, callback: CallbackFn): void; + /** + * Updates a webhook. + */ + update( + id: string, + params: Webhooks.UpdateParameters, + callback: CallbackFn + ): void; + /** + * Retrieves a list of webhooks. + */ + list(limit: number, offset: number, callback: CallbackFn): void; + /** + * Deletes webhook + */ + delete(id: string, callback: CallbackFn): void; + }; + }; } declare function messagebird(accessKey: string, timeout?: number): MessageBird; From e47372cd38a3450fe1b258eb92e4c75fe1758cae Mon Sep 17 00:00:00 2001 From: Elmar Burke Date: Mon, 28 Jan 2019 11:44:50 +0100 Subject: [PATCH 6/7] add mms typings --- types/index.d.ts | 22 +++++++++++++++ types/mms.d.ts | 72 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 94 insertions(+) create mode 100644 types/mms.d.ts diff --git a/types/index.d.ts b/types/index.d.ts index 19e21b3..2e256d7 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -20,6 +20,7 @@ import { ReplyConversationParameters, Webhooks } from './conversations'; +import { MmsObject, MmsParameter } from './mms'; type CallbackFn = (err: Error | null, res: T | null) => void; @@ -231,6 +232,27 @@ export interface MessageBird { */ delete(id: string, callback: CallbackFn): void; }; + /** + * MessageBird's MMS Messaging API enables you to send and receive MMS messages to and from a selected group of countries. Currently you can only send MMS within the US and Canada. + * + * Messages are identified by a unique ID. And with this ID you can always check the status of the MMS message through the provided endpoint. + */ + mms: { + /** + * Retrieves the information of an existing sent MMS message. You only need to supply the unique message id that was returned upon creation. + */ + read(id: string, callback: CallbackFn): void; + + /** + * + * Creates a new MMS message object. MessageBird returns the created message object with each request. Per request, a max of 50 recipients can be entered. + */ + create(params: MmsParameter, callback: CallbackFn): void; + + list(limit: number, offset: number, callback: CallbackFn): void; + + delete(id: string, callback: CallbackFn): void; + }; }; } diff --git a/types/mms.d.ts b/types/mms.d.ts new file mode 100644 index 0000000..7783f9c --- /dev/null +++ b/types/mms.d.ts @@ -0,0 +1,72 @@ +import { datetime, msisdn } from 'general'; +import { Recipients } from 'messages'; + +export interface MmsObject { + /** A unique ID which is created on the MessageBird platform and is returned upon creation of the object. */ + id: string; + + /** The URL of the created object. */ + href: string; + + /** + * Tells you if the message is sent or received. + * mt: mobile terminated (sent to mobile) + * mo: mobile originated (received from mobile) + */ + direction: 'mt' | 'mo'; + + /** The sender/source address of the message. This has to be the dedicated MMS virtual mobile number (including country code) for either the US/CA. */ + originator: string; + + recipients: Recipients; + + /** The subject of the MMS message. */ + subject: string; + + /** The body of the MMS message. */ + body: string; + + /** An array with URL's to the media attachments you want to send as part of the MMS message. */ + mediaUrls: string[]; + + /** A client reference */ + reference: string; + + /** The scheduled date and time of the message in RFC3339 format (Y-m-d\TH:i:sP) */ + scheduledDatetime: datetime; + + /** The date and time of the creation of the message in RFC3339 format (Y-m-d\TH:i:sP) */ + createdDatetime: datetime; +} + +export interface BasicMmsParameter { + /* The sender of the message. This can be a telephone number (including country code - E.164) or an alphanumeric string. In case of an alphanumeric string, the maximum length is 11 characters.*/ + originator: msisdn; + /* The array of recipients MSISDNs, E.164 formatted */ + recipients: msisdn[]; + + /* The subject of the MMS message, UTF-8 encoded */ + subject?: string; + /* A client reference */ + reference?: string; + /* The scheduled date and time of the message in RFC3339 format (Y-m-d\TH:i:sP) */ + scheduledDatetime?: datetime; +} + +export interface MmsBodyOnlyParameter extends BasicMmsParameter { + /* The body of the MMS message, UTF-8 encoded. */ + body: string; +} +export interface MmsMediaUrlsOnlyParameter extends BasicMmsParameter { + /* Array of URL's of attachments of the MMS message. See media attachmentsfor more information about attachments. Body or mediaUrls is required */ + mediaUrls: string[]; +} + +export interface MmsMediaUrlsAndBodyParameter + extends MmsBodyOnlyParameter, + MmsMediaUrlsOnlyParameter {} + +export type MmsParameter = + | MmsBodyOnlyParameter + | MmsMediaUrlsOnlyParameter + | MmsMediaUrlsAndBodyParameter; From eeb7831383e620264ecb71ca01553eff2aafce20 Mon Sep 17 00:00:00 2001 From: Elmar Burke Date: Mon, 28 Jan 2019 12:01:41 +0100 Subject: [PATCH 7/7] fix imports and more types --- types/contact.d.ts | 2 +- types/conversations.d.ts | 16 ++++++++++------ types/lookup.d.ts | 4 ++-- types/messages.d.ts | 2 +- types/mms.d.ts | 4 ++-- 5 files changed, 16 insertions(+), 12 deletions(-) diff --git a/types/contact.d.ts b/types/contact.d.ts index 2157f23..3e8cf87 100644 --- a/types/contact.d.ts +++ b/types/contact.d.ts @@ -1,4 +1,4 @@ -import { datetime } from 'general'; +import { datetime } from './general'; export interface Contact { /** A unique random ID which is created on the MessageBird platform and is returned upon creation of the object. */ diff --git a/types/conversations.d.ts b/types/conversations.d.ts index fcfb42c..5b4218f 100644 --- a/types/conversations.d.ts +++ b/types/conversations.d.ts @@ -1,5 +1,5 @@ -import { Language } from 'parsimmon'; -import { datetime } from 'general'; +import { datetime } from './general'; +import { languages } from './voice_messages'; export interface StartConversationParameter { /** The type of the message content. */ @@ -44,17 +44,21 @@ export interface TextContent { export interface ImageContent { /** Required for type image. An object of the form {"url": ""} containing the url of the remote media file. */ - image: object; + image: File; } export interface AudioContent { /** Required for type video. An object of the form {"url": ""} containing the url of the remote media file. */ - video: object; + video: File; } export interface FileContent { /** Required for type file. An object of the form {"url": ""} containing the url of the remote media file. */ - file: object; + file: File; +} + +export interface File { + url: string; } export interface LocationContent { @@ -87,7 +91,7 @@ export interface HSMLanguage { */ policy: 'fallback' | 'deterministic'; /** The code of the language or locale to use, accepts both language and language_locale formats (e.g., en or en_US). */ - code: Language; + code: languages; } export type HSMLocalizableParameters = diff --git a/types/lookup.d.ts b/types/lookup.d.ts index c2011ae..cb7e907 100644 --- a/types/lookup.d.ts +++ b/types/lookup.d.ts @@ -1,5 +1,5 @@ -import { datetime } from 'general'; -import { Hlr } from 'hlr'; +import { datetime } from './general'; +import { Hlr } from './hlr'; export type numberType = | 'fixed line' diff --git a/types/messages.d.ts b/types/messages.d.ts index ccd383f..ce2240c 100644 --- a/types/messages.d.ts +++ b/types/messages.d.ts @@ -1,4 +1,4 @@ -import { datetime, msisdn } from 'general'; +import { datetime, msisdn } from './general'; export type dataCoding = 'plain' | 'unicode' | 'auto'; export type mclass = 0 | 1; diff --git a/types/mms.d.ts b/types/mms.d.ts index 7783f9c..a756a5f 100644 --- a/types/mms.d.ts +++ b/types/mms.d.ts @@ -1,5 +1,5 @@ -import { datetime, msisdn } from 'general'; -import { Recipients } from 'messages'; +import { datetime, msisdn } from './general'; +import { Recipients } from './messages'; export interface MmsObject { /** A unique ID which is created on the MessageBird platform and is returned upon creation of the object. */