-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.ts
149 lines (134 loc) · 3.55 KB
/
types.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
// Copyright 2020 KwanJunWen. All rights reserved. MIT license.
export interface OneWayClient {
sendSMS(input: SendSMSInput): Promise<SendSMSOutput>;
checkTransactionStatus(
input: CheckTransactionStatusInput,
): Promise<CheckTransactionStatusOutput>;
checkCreditBalance(): Promise<CheckCreditBalanceOutput>;
}
/**
* URL path to access OneWaySMS API.
* "api.aspx" - MT URL path.
* "bulktrx.aspx" - Check MT transaction URL path.
* "bulkcredit.aspx" - Check credit balance URL path.
*/
export type OneWayURLPath = "api.aspx" | "bulktrx.aspx" | "bulkcredit.aspx";
/**
* OneWaySMS API request URL parameters.
*/
export type OneWayURLParams = Record<
| "apiusername"
| "apipassword"
| "senderid"
| "mobileno"
| "languagetype"
| "message"
| "mtid",
string
>;
export interface OneWayClientConfig
extends OneWayUserCredentials, OneWaySenderID {
/**
* BaseURL to onewaysms gateway exluding trailing "/".
* For example: http://gatewayd2.onewaysms.sg:10002
*/
baseURL: string;
}
export interface OneWayUserCredentials {
/**
* Username for your API. (can be obtain under API section once you have log into your account).
*/
apiUsername: string;
/**
* Password for your API. (can be obtain under API section once you have log into your account).
*/
apiPassword: string;
}
export interface OneWaySenderID {
/**
* Refer to sender. Field can take up to 11 alphanumeric characters.
*/
senderID: string;
}
/**
* Language Type of the SMS. Indicating the type of sms sent.
* "1" - Normal Text message (160 characters as 1 MT)
* "2" - Unicode Text message (70 characters as 1 MT)
*/
export type LanguageType = "1" | "2";
export type SendSMSURLParams = Pick<
OneWayURLParams,
| "apiusername"
| "apipassword"
| "senderid"
| "mobileno"
| "languagetype"
| "message"
>;
export interface SendSMSInput extends Partial<OneWaySenderID> {
/**
* Language Type of the SMS. Refer to LanguageType for details.
*/
languageType?: LanguageType;
/**
* Content of the SMS.
*
* Example, if languagetype set to 1, and message
* has content with length 200, 2 SMS will be sent.
*
* SMS can be combined. 7 characters will be used to combine.
* Below are the character count:
*
* 1 SMS = 160 characters
* 2 SMS = 306 characters (14 characters for joining)
* 3 SMS = 459 characters (21 characters for joining)
*
* We recommend sending up to maximum up to 3 SMS.
*/
message: string;
/**
* Phone number of recipient. Phone number must include country code.
* For example: 6581234567.
*/
mobileNo: string | string[];
}
export interface SendSMSOutput {
/**
* Mobile terminating ID(s) from the send SMS result.
*/
mtIDs: number[];
}
export type CheckTransactionStatusURLParams = Pick<OneWayURLParams, "mtid">;
export interface CheckTransactionStatusInput {
/**
* Mobile terminating ID returned from the send SMS result.
*/
mtID: number;
}
export interface CheckTransactionStatusOutput {
/**
* Status of the mobile terminating transaction.
* Refer to MTTransactionStatus for more details.
*/
status: MTTransactionStatus;
}
export type CheckCreditBalanceURLParams = Pick<
OneWayURLParams,
"apiusername" | "apipassword"
>;
export interface CheckCreditBalanceOutput {
/**
* Remaining credit balance for the account of this client's config.
*/
creditBalance: number;
}
export enum MTTransactionStatus {
/**
* Successfully sent message.
*/
Success = "success",
/**
* Message has been delivered to Telco.
*/
TelcoDelivered = "telco_delivered",
}