forked from habbes/ussd-menu-builder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.d.ts
201 lines (152 loc) · 4.37 KB
/
index.d.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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
/// <reference types="node" />
// Type definitions for ussd-menu-builder 1.0.0
// Project: ussd-menu-builder
// Definitions by: Jason Schapiro <yono38@gmail.com>
import { EventEmitter } from "events";
export = UssdMenu;
declare class UssdState {
constructor(menu: UssdMenu);
defaultNext?: string;
menu: UssdMenu;
name: string;
run(): void;
val: string;
}
declare class UssdMenu extends EventEmitter {
constructor(opts?: UssdMenu.UssdMenuOptions);
session: any;
provider: UssdMenu.UssdMenuProvider;
args: UssdMenu.UssdGatewayArgs;
states: Array<UssdState>;
result: UssdResponseWrapper;
val: string;
callOnResult(): void;
con(response: UssdResponse): void;
end(response: UssdResponse): void;
formatResponse(response: UssdResponseWrapper, formatter?: (response: UssdResponseWrapper)=> string): any;
getRoute(
args: UssdMenu.UssdGatewayArgs | UssdMenu.HubtelArgs
): Promise<string>;
go(state: string): void;
goStart(): void;
mapArgs(
args: UssdMenu.UssdGatewayArgs | UssdMenu.HubtelArgs
): UssdMenu.UssdGatewayArgs;
onResult?(result: UssdResponseWrapper | UssdMenu.HubtelResponse): void;
resolveRoute(route: string, callback: Function): void;
resolve?(value: string): void;
run(args: UssdMenu.UssdGatewayArgs, onResult?: Function): Promise<UssdResponseWrapper>;
runState(state: UssdState): void;
sessionConfig(config: UssdMenu.UssdSessionConfig): void;
startState(options: UssdMenu.UssdStateOptions): void;
state(name: string, options: UssdMenu.UssdStateOptions): UssdMenu;
testLinkRule(rule: string, val: string): boolean;
static START_STATE: string;
}
/*~ If you want to expose types from your module as well, you can
*~ place them in this block.
*/
declare namespace UssdMenu {
interface NextState {
[state: string]: Function | string;
}
interface UssdGatewayArgs {
text: string;
phoneNumber: string;
sessionId: string;
serviceCode: string;
operator: string;
}
interface HubtelResponse {
Type: "Response" | "Release";
Message: string;
}
interface HubtelArgs {
Mobile: string;
SessionId: string;
ServiceCode: string;
Type: "Initiation" | "Response" | "Release" | "Timeout";
Message: string;
Operator: "Tigo" | "Airtel" | "MTN" | "Vodafone" | "Safaricom" | "Orange";
Sequence: number;
ClientState?: any;
}
type UssdMenuProvider = "africasTalking" | "hubtel" | "mikashboks";
interface UssdMenuOptions {
provider?: UssdMenuProvider;
}
interface UssdStateOptions {
run?(): void;
next?: NextState;
defaultNext?: string;
}
interface UssdSessionConfig {
start(sessionId: string, callback?: Function): Promise<any> | void;
end(sessionId: string, callback?: Function): Promise<any> | void;
get(
sessionId: string,
key: string,
callback?: Function
): Promise<any> | void;
set(
sessionId: string,
key: string,
value: any,
callback?: Function
): Promise<any> | void;
getAll(sessionId: string, callback?: Function): Promise<any> | void;
}
interface Link {
href?: string;
text?: string;
key?: string;
}
interface ContentPageResponse {
__typeName: "ContentPageResponse"
descr?: string;
content?: string;
links?: Link[];
nav?: 'default' | 'stop' | 'end';
volatile?: boolean;
ismenu?: boolean;
autoIncrementKeys?: boolean;
}
interface RedirectPageResponse {
__typeName: "RedirectPageResponse"
descr?: string;
erl?: string;
encodeUrl?: boolean;
nav?: 'default' | 'stop' | 'end';
volatile?: boolean;
ismenu?: boolean;
}
interface FormPageResponse {
__typeName: "FormPageResponse"
descr?: string;
prompt?: string;
var?: string;
action?: string;
nav?: 'default' | 'stop' | 'end';
volatile?: boolean;
ismenu?: boolean;
kind?: 'alpha' | 'digits' | 'alphanum';
req?: {
query: {
[key: string]: string;
};
};
}
interface EmptyPageResponse {
__typeName: "EmptyPageResponse"
descr?: string;
nav?: 'default' | 'stop' | 'end';
}
type UssdResponse = ContentPageResponse | RedirectPageResponse | FormPageResponse | EmptyPageResponse;
type UssdResponseWrapper = {
response: UssdResponse;
hasNext: boolean;
}
interface UssdResponseFormatter {
(response: UssdResponseWrapper): string;
}
}