diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..24af3fc --- /dev/null +++ b/index.d.ts @@ -0,0 +1,134 @@ +export interface UserProfile { + id: string, + name: string, + avatar: string, + /** iso alpha 2 code */ + country: string, + language: string, + apiVersion: number; +} + +export interface ReceivedTextMessage { + text: string, + /** milliseconds */ + timestamp: number, + token: string, + trackingData: any, + keyboard: any, + requiredArguments: string[], + minApiVersion: undefined; +} + +type ConversationStarted = (userProfile: UserProfile, + isSubscribed: boolean, + context: any, + onFinish: any) => any; + +export interface Bot { + onConversationStarted: (fn: ConversationStarted)=> void; + onTextMessage: (pattern: RegExp, callback: (message: ReceivedTextMessage, response: any) => any) => any; + middleware: () => any; + onError: (callback: (error: any) => any) => any; + setWebhook: (webhook: string) => Promise; + onSubscribe: (callback: (response: Response) => void ) => void; + sendMessage: (minUserProfile: { id: string }, messages: any[]) => Promise; + onUnsubscribe: (callback: (userId: string) => void) => void; + on: (eventName: string, handler: any)=>void; +} + +export interface Keyboard { + Type: 'keyboard', + /** hex color */ + BgColor: string; + Buttons: KeyboardButton[]; + InputFieldState: 'hidden' | 'regular' | 'minimized', +} + +export interface KeyboardButton { + Columns?: number, + Rows?: number, + ActionType?: "reply" | "open-url" | "none", + ActionBody: string, + /** hex color */ + BgColor?: string; + Text: string; + TextVAlign?: string, + TextHAlign?: string, + TextSize?: 'regular' + Silent?: boolean; + OpenURLType?: string, + InternalBrowser?: { + ActionButton?: string; + ActionPredefinedURL?: string; + Mode?: string; + CustomTitle?: string, + } +} + +export interface RichMedia { + ButtonsGroupColumns: number, + ButtonsGroupRows: number, + BgColor: string, + Buttons: RichMediaButton[] +} + +export interface RichMediaButton { + Columns?: number; + Rows?: number; + ActionType?: "reply" | "open-url" | "none"; + ActionBody?: string; + Image?: string; + OpenURLType?: string; + Text?: string; + TextSize?: string; + TextVAlign?: string; + TextHAlign?: string; + BgColor?: string; + InternalBrowser?: { + ActionButton: string; + ActionPredefinedURL?: string; + } + Silent?: boolean; +} + +export interface Response { + userProfile: UserProfile, + send: (messages: any | any[]) => void; +} + +export interface StickerMessage { + new (stickerId: number): StickerMessage; +} + +export interface KeyboardMessage { + new ( + keyboard: Keyboard, + optionalTrackingData?: string, + timestamp?: string, + token?: string, + minApiVersion?: number, + ): KeyboardMessage; +} + +export interface RichMediaMessage { + new ( + richMedia: RichMedia, + optionalKeyboard?: Keyboard, + optionalTrackingData?: string, + timestamp?: string, + token?: string, + optionalAltText?: string, + minApiVersion?: number, + ): RichMediaMessage; +} + +export interface TextMessage { + new ( + message: string, + keyboard?: Keyboard, + optionalTrackingData?: string, + timestamp?: string, + token?: string, + minApiVersion?: number, + ): TextMessage; +} diff --git a/package.json b/package.json index 96e686c..5c8af59 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,7 @@ "description": "A bot interface to work with Viber API", "author": "Viber LTD", "engine-strict": true, + "types": "index.d.ts", "engines": { "node": ">=5", "npm": ">=3" @@ -32,4 +33,4 @@ "express": "^4.14.0", "nodeunit": "^0.11.3" } -} \ No newline at end of file +}