UNPKG

1.86 kBJavaScriptView Raw
1// @flow
2
3export type Config = {|
4 +mainframe_secret: string,
5 +mainframe_url: string,
6 +port: number,
7|}
8
9export type ClientContext = {|
10 +user: {
11 +id: string,
12 +username: string,
13 +name: string,
14 },
15 +conversation?: {
16 +id: string,
17 +subject: ?string,
18 +type: 'bot' | 'direct' | 'default' | 'space',
19 },
20 +organization?: {
21 +id: string,
22 +username: string,
23 +name: string,
24 },
25 +subscription_token?: string,
26|}
27
28export type PostPayload = {|
29 +user_id: string,
30 +data: Object,
31 +context: ClientContext,
32|}
33
34type SendMessagePayload = {
35 conversation_id: string,
36 message?: string,
37 data?: Object,
38}
39
40type SubscriptionPayload = {
41 subscription_token: string,
42 label?: string,
43}
44
45type SubscriptionResponse = {
46 subscription_id: string,
47}
48
49export type BotContext = {|
50 +config: Config,
51 +callMainframe: (endpoint: string, data?: Object) => Promise<void | Object>,
52 +sendMessage: (payload: SendMessagePayload) => Promise<void>,
53 +createSubscription: (
54 payload: SubscriptionPayload,
55 ) => Promise<SubscriptionResponse>,
56 +editSubscription: (
57 payload: SubscriptionPayload,
58 ) => Promise<SubscriptionResponse>,
59|}
60
61export type BotResponse = {|
62 success: boolean,
63 message?: string,
64 data?: Object,
65|}
66
67export type Handlers = {|
68 enable?: (payload: { user_id: string }) => void,
69 disable?: (payload: { user_id: string }) => void,
70 conversation_added?: (payload: {
71 user_id: string,
72 conversation_id: string,
73 }) => void,
74 conversation_removed?: (payload: {
75 user_id: string,
76 conversation_id: string,
77 }) => void,
78 edit_subscription?: (payload: {
79 user_id: string,
80 conversation_id: string,
81 subscription_id: string,
82 }) => void,
83 delete_subscription?: (payload: { subscription_id: string }) => void,
84 post?: (payload: PostRequest) => BotResponse | Promise<BotResponse>,
85|}