tock / ai.tock.bot.connector.messenger / MessengerConnector

# MessengerConnector

`class MessengerConnector : ConnectorBase` (source)

Contains built-in checks to ensure that two MessageRequest for the same recipient are sent sequentially.

### Functions

#### addSuggestions | Returns a ConnectorMessage with the specified list of suggestions. If the connector does not support suggestions, returns null. `fun addSuggestions(text: CharSequence, suggestions: List<CharSequence>): BotBus.() -> ConnectorMessage?` Updates a ConnectorMessage with the specified list of suggestions. Default returns message unmodified. `fun addSuggestions(message: ConnectorMessage, suggestions: List<CharSequence>): BotBus.() -> ConnectorMessage?`
#### getSecondaryReceivers | Returns the secondary receivers (handover protocol) if the app is the primary receiver, null either. `fun getSecondaryReceivers(): List<SecondaryReceiverData>?`
#### getThreadOwner | Returns the current thread owner (handover protocol). `fun getThreadOwner(userId: PlayerId): String?`
#### loadProfile | Load user preferences - default implementation returns null. `fun loadProfile(callback: ConnectorCallback, userId: PlayerId): UserPreferences`
#### notify | Sends a notification to the connector. A BotBus is created and the corresponding story is called. `fun notify(controller: ConnectorController, recipientId: PlayerId, intent: IntentAware, step: StoryStep<out StoryHandlerDefinition>?, parameters: Map<String, String>, notificationType: ActionNotificationType?, errorListener: (Throwable) -> Unit): Unit`
#### passThreadControl | Passes thread control. `fun passThreadControl(userId: PlayerId, targetAppId: String, metadata: String? = null): SendResponse?`
#### refreshProfile | Refresh user preferences - default implementation returns null. Only not null values are taken into account. `fun refreshProfile(callback: ConnectorCallback, userId: PlayerId): UserPreferences?`
#### register | Registers the connector for the specified controller. `fun register(controller: ConnectorController): Unit`
#### requestThreadControl | Sends a request to get thread control. `fun requestThreadControl(userId: PlayerId, metadata: String? = null): SendResponse?`
#### send | Send the event to messenger asynchronously. Contains checks to ensure that two Action for the same recipient are sent sequentially. `fun send(event: Event, callback: ConnectorCallback, delayInMs: Long): Unit`
#### sendCustomEvent | Send a custom event to messenger `fun sendCustomEvent(customEventRequest: CustomEventRequest): Unit`
#### sendEvent | Send an action to messenger. `fun sendEvent(event: Event, transformMessageRequest: (MessageRequest) -> MessageRequest = { it }, postMessage: (String) -> Unit = {}, transformActionRequest: (ActionRequest) -> ActionRequest = { it }, errorListener: (Throwable) -> Unit = {}): SendResponse?`
#### sendOptInEvent | Send action after an optin request, using the recipient.user_ref property. See https://developers.facebook.com/docs/messenger-platform/plugin-reference/checkbox-plugin#implementation for more details. `fun sendOptInEvent(event: Event): Unit`
#### takeThreadControl | Takes the thread control. `fun takeThreadControl(userId: PlayerId, metadata: String? = null): SendResponse?`
#### toConnectorMessage | Maps a MediaMessage into a ConnectorMessage. If toConnectorMessage returns an empty list, the mapping is not supported for this connector. Default returns an empty list. `fun toConnectorMessage(message: MediaMessage): BotBus.() -> List<ConnectorMessage>`
#### unregister | Unregisters the connector. `fun unregister(controller: ConnectorController): Unit`

### Companion Object Functions

#### getConnectorById | `fun getConnectorById(connectorId: String): MessengerConnector?`
#### healthcheck | `fun healthcheck(): Boolean`