// @flow export type PartialConfig = { +mainframe_secret?: string, +mainframe_url?: string, +port?: number, } export type Config = {| +mainframe_secret: string, +mainframe_url: string, +port: number, |} export type ServerContext = {| +user_id: string, +conversation_id?: string, +subscription_id?: string, +subscription_token?: string, |} export type PostPayload = {| +data: Object, +context: ServerContext, |} type SendMessagePayload = { conversation_id: string, message?: string, data?: Object, } type SubscriptionResponse = {| +subscription_id: string, |} export type BotContext = {| +config: Config, +callMainframe: (endpoint: string, data?: Object) => Promise, +sendMessage: (payload: SendMessagePayload) => Promise, +setupSubscription: (payload: { subscription_token: string, label: string, }) => Promise, +editSubscription: (payload: { subscription_token: string, label?: string, }) => Promise, |} export type BotResponse = {| success: boolean, message?: string, data?: Object, |} export type Handlers = {| +enable?: (payload: { user_id: string }, context: BotContext) => void, +disable?: (payload: { user_id: string }, context: BotContext) => void, +conversation_added?: ( payload: {| +user_id: string, +conversation_id: string, |}, context: BotContext, ) => void, +conversation_removed?: ( payload: {| +user_id: string, +conversation_id: string, |}, context: BotContext, ) => void, +edit_subscription?: ( payload: {| +user_id: string, +conversation_id: string, +subscription_id: string, |}, context: BotContext, ) => void, +delete_subscription?: ( payload: {| +subscription_id: string, |}, context: BotContext, ) => void, +mention?: ( payload: {| +user_id: string, +conversation_id: string, +text: string, |}, context: BotContext, ) => void, +post?: ( payload: PostPayload, context: BotContext, ) => BotResponse | Promise, +preview?: ( payload: {| +user_id: string, +link: string, |}, context: BotContext, ) => BotResponse | Promise, |}