UNPKG

2.3 kBJavaScriptView Raw
1// @flow
2
3export type PartialConfig = {
4 +mainframe_secret?: string,
5 +mainframe_url?: string,
6 +port?: number,
7}
8
9export type Config = {|
10 +mainframe_secret: string,
11 +mainframe_url: string,
12 +port: number,
13|}
14
15export type ServerContext = {|
16 +user_id: string,
17 +conversation_id?: string,
18 +subscription_id?: string,
19 +subscription_token?: string,
20|}
21
22export type PostPayload = {|
23 +data: Object,
24 +context: ServerContext,
25|}
26
27type SendMessagePayload = {
28 conversation_id: string,
29 message?: string,
30 data?: Object,
31}
32
33type SubscriptionResponse = {|
34 +subscription_id: string,
35|}
36
37export type BotContext = {|
38 +config: Config,
39 +callMainframe: (endpoint: string, data?: Object) => Promise<void | Object>,
40 +sendMessage: (payload: SendMessagePayload) => Promise<void>,
41 +setupSubscription: (payload: {
42 subscription_token: string,
43 label: string,
44 }) => Promise<SubscriptionResponse>,
45 +editSubscription: (payload: {
46 subscription_token: string,
47 label?: string,
48 }) => Promise<SubscriptionResponse>,
49|}
50
51export type BotResponse = {|
52 success: boolean,
53 message?: string,
54 data?: Object,
55|}
56
57export type Handlers = {|
58 +enable?: (payload: { user_id: string }, context: BotContext) => void,
59 +disable?: (payload: { user_id: string }, context: BotContext) => void,
60 +conversation_added?: (
61 payload: {|
62 +user_id: string,
63 +conversation_id: string,
64 |},
65 context: BotContext,
66 ) => void,
67 +conversation_removed?: (
68 payload: {|
69 +user_id: string,
70 +conversation_id: string,
71 |},
72 context: BotContext,
73 ) => void,
74 +edit_subscription?: (
75 payload: {|
76 +user_id: string,
77 +conversation_id: string,
78 +subscription_id: string,
79 |},
80 context: BotContext,
81 ) => void,
82 +delete_subscription?: (
83 payload: {|
84 +subscription_id: string,
85 |},
86 context: BotContext,
87 ) => void,
88 +mention?: (
89 payload: {|
90 +user_id: string,
91 +conversation_id: string,
92 +text: string,
93 |},
94 context: BotContext,
95 ) => void,
96 +post?: (
97 payload: PostPayload,
98 context: BotContext,
99 ) => BotResponse | Promise<BotResponse>,
100 +preview?: (
101 payload: {|
102 +user_id: string,
103 +link: string,
104 |},
105 context: BotContext,
106 ) => BotResponse | Promise<BotResponse>,
107|}