1 |
|
2 |
|
3 | export type Config = {|
|
4 | +mainframe_secret: string,
|
5 | +mainframe_url: string,
|
6 | +port: number,
|
7 | |}
|
8 |
|
9 | export 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?: {
|
26 | +id?: string,
|
27 | +token: string,
|
28 | },
|
29 | |}
|
30 |
|
31 | export type PostPayload = {|
|
32 | +user_id: string,
|
33 | +data: Object,
|
34 | +context: ClientContext,
|
35 | |}
|
36 |
|
37 | type SendMessagePayload = {
|
38 | conversation_id: string,
|
39 | message?: string,
|
40 | data?: Object,
|
41 | }
|
42 |
|
43 | type SubscriptionResponse = {
|
44 | subscription_id: string,
|
45 | }
|
46 |
|
47 | export type BotContext = {|
|
48 | +config: Config,
|
49 | +callMainframe: (endpoint: string, data?: Object) => Promise<void | Object>,
|
50 | +sendMessage: (payload: SendMessagePayload) => Promise<void>,
|
51 | +setupSubscription: (payload: {
|
52 | subscription_token: string,
|
53 | label: string,
|
54 | }) => Promise<SubscriptionResponse>,
|
55 | +editSubscription: (payload: {
|
56 | subscription_token: string,
|
57 | label?: string,
|
58 | }) => Promise<SubscriptionResponse>,
|
59 | |}
|
60 |
|
61 | export type BotResponse = {|
|
62 | success: boolean,
|
63 | message?: string,
|
64 | data?: Object,
|
65 | |}
|
66 |
|
67 | export type Handlers = {|
|
68 | +enable?: (payload: { user_id: string }, context: BotContext) => void,
|
69 | +disable?: (payload: { user_id: string }, context: BotContext) => void,
|
70 | +conversation_added?: (
|
71 | payload: {
|
72 | user_id: string,
|
73 | conversation_id: string,
|
74 | },
|
75 | context: BotContext,
|
76 | ) => void,
|
77 | +conversation_removed?: (
|
78 | payload: {
|
79 | user_id: string,
|
80 | conversation_id: string,
|
81 | },
|
82 | context: BotContext,
|
83 | ) => void,
|
84 | +edit_subscription?: (
|
85 | payload: {
|
86 | user_id: string,
|
87 | conversation_id: string,
|
88 | subscription_id: string,
|
89 | },
|
90 | context: BotContext,
|
91 | ) => void,
|
92 | +delete_subscription?: (
|
93 | payload: { subscription_id: string },
|
94 | context: BotContext,
|
95 | ) => void,
|
96 | +post?: (
|
97 | payload: PostPayload,
|
98 | context: BotContext,
|
99 | ) => BotResponse | Promise<BotResponse>,
|
100 | |}
|