tock / ai.tock.bot.connector.messenger

Package ai.tock.bot.connector.messenger

MessengerConnector implementation

Types

MessengerConnector

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

class MessengerConnector : ConnectorBase

Annotations

MessengerHandler

To specify ConnectorStoryHandler for Messenger connector. KClass passed as value of this annotation must have a primary constructor with a single not optional StoryHandlerDefinitionBase argument.

annotation class MessengerHandler

Properties

messengerConnectorType

The Messenger connector type.

val messengerConnectorType: ConnectorType

Functions

attachment

Creates an attachment.

fun <T : Bus<T>> T.attachment(attachmentUrl: String, type: AttachmentType, vararg quickReplies: QuickReply): AttachmentMessage
fun <T : Bus<T>> T.attachment(attachmentUrl: String, type: AttachmentType, quickReplies: List<QuickReply>): AttachmentMessage

audio

Creates an audio file as attachment (https://developers.facebook.com/docs/messenger-platform/reference/send-api/#attachment).

fun <T : Bus<T>> T.audio(audioUrl: String, vararg quickReplies: QuickReply): AttachmentMessage
fun <T : Bus<T>> T.audio(audioUrl: String, quickReplies: List<QuickReply>): AttachmentMessage

buttonsTemplate

Creates a button template https://developers.facebook.com/docs/messenger-platform/send-api-reference/button-template

fun I18nTranslator.buttonsTemplate(text: CharSequence, vararg actions: UserAction): AttachmentMessage
fun I18nTranslator.buttonsTemplate(text: CharSequence, actions: List<UserAction>): AttachmentMessage

callToButton

fun I18nTranslator.callToButton(title: CharSequence, phoneNumber: String): CallButton

emailQuickReply

Creates a quick reply email.

fun emailQuickReply(): QuickReply

endForMessenger

Sends a Messenger message as last bot answer, only if the ConnectorType of the current Bus is messengerConnectorType.

fun <T : Bus<T>> T.endForMessenger(delay: Long = defaultDelay(currentAnswerIndex), messageProvider: T.() -> MessengerConnectorMessage): T

genericElement

Creates a generic element.

fun I18nTranslator.genericElement(title: CharSequence, subtitle: CharSequence? = null, imageUrl: String? = null, buttons: List<Button>? = null): Element

genericTemplate

Creates a generic template.

fun genericTemplate(vararg elements: Element): AttachmentMessage
fun genericTemplate(elements: List<Element>, quickReplies: List<QuickReply>): AttachmentMessage
fun genericTemplate(elements: List<Element>, vararg quickReplies: QuickReply): AttachmentMessage

image

Creates an image as attachment (https://developers.facebook.com/docs/messenger-platform/reference/send-api/#attachment).

fun <T : Bus<T>> T.image(imageUrl: String, vararg quickReplies: QuickReply): AttachmentMessage
fun <T : Bus<T>> T.image(imageUrl: String, quickReplies: List<QuickReply>): AttachmentMessage

loginButton

Provides a Log In Button.

fun loginButton(url: String): LoginButton

logoutButton

Provides a Log Out Button.

fun logoutButton(): LogoutButton

mediaTemplate

Creates a media template https://developers.facebook.com/docs/messenger-platform/send-messages/template/media

fun mediaTemplate(mediaUrl: String, mediaType: MediaType = MediaType.image, sharable: Boolean = false, vararg actions: UserAction): AttachmentMessage
fun mediaTemplate(mediaUrl: String, mediaType: MediaType = MediaType.image, sharable: Boolean = false, actions: List<UserAction> = emptyList()): AttachmentMessage

nlpPostbackButton

This button does not use any custom payload, but the textToSend will we parsed by the NLP engine.

fun I18nTranslator.nlpPostbackButton(title: CharSequence, textToSend: CharSequence = title): PostbackButton

nlpQuickReply

This quick reply does not use any custom payload, but the textToSend will we parsed by the NLP engine.

fun I18nTranslator.nlpQuickReply(title: CharSequence, textToSend: CharSequence = title, imageUrl: String? = null): QuickReply

postbackButton

Creates a postback button.

fun <T : Bus<T>> T.postbackButton(title: CharSequence, targetIntent: IntentAware, vararg parameters: Pair<String, String>): PostbackButton
fun <T : Bus<T>> T.postbackButton(title: CharSequence, targetIntent: IntentAware, parameters: Parameters): PostbackButton
fun <T : Bus<T>> T.postbackButton(title: CharSequence, targetIntent: IntentAware, step: StoryStep<out StoryHandlerDefinition>? = null, parameters: Parameters): PostbackButton
fun <T : Bus<T>> T.postbackButton(title: CharSequence, targetIntent: IntentAware, step: StoryStep<out StoryHandlerDefinition>? = null, vararg parameters: Pair<String, String>): PostbackButton

quickReply

Creates a quick reply.

fun <T : Bus<T>> T.quickReply(title: CharSequence, targetIntent: IntentAware, parameters: Parameters): QuickReply
fun <T : Bus<T>> T.quickReply(title: CharSequence, targetIntent: IntentAware, imageUrl: String? = null, step: StoryStep<out StoryHandlerDefinition>? = null, parameters: Parameters): QuickReply
fun <T : Bus<T>> T.quickReply(title: CharSequence, targetIntent: IntentAware, imageUrl: String? = null, step: StoryStep<out StoryHandlerDefinition>? = null, parameters: Collection<Pair<String, String>>): QuickReply
fun <T : Bus<T>> T.quickReply(title: CharSequence, targetIntent: IntentAware, imageUrl: String? = null, step: StoryStep<out StoryHandlerDefinition>? = null, parameters: Map<String, String>): QuickReply

Create a quick reply.

fun <T : Bus<T>> T.quickReply(title: CharSequence, targetIntent: IntentAware, imageUrl: String? = null, step: StoryStep<out StoryHandlerDefinition>? = null, vararg parameters: Pair<String, String>): QuickReply

sendToMessenger

Sends a Messenger message only if the ConnectorType of the current Bus is messengerConnectorType.

fun <T : Bus<T>> T.sendToMessenger(delay: Long = defaultDelay(currentAnswerIndex), messageProvider: T.() -> MessengerConnectorMessage): T

standaloneMessengerAnswer

Used to generate a MessengerConnectorMessage event, usually sent later by MessengerConnector.send or MessengerConnector.sendOptInEvent.

fun standaloneMessengerAnswer(playerId: PlayerId, applicationId: String, recipientId: PlayerId, lastAnswer: Boolean = true, priority: ActionPriority = ActionPriority.normal, notificationType: ActionNotificationType? = null, messageProvider: () -> MessengerConnectorMessage): SendSentence

standaloneMessengerAnswers

Used to generate multiple MessengerConnectorMessage events, usually sent later by MessengerConnector.send or MessengerConnector.sendOptInEvent.

fun standaloneMessengerAnswers(playerId: PlayerId, applicationId: String, recipientId: PlayerId, priority: ActionPriority = ActionPriority.normal, notificationType: ActionNotificationType? = null, messagesProvider: () -> List<MessengerConnectorMessage>): List<SendSentence>

standaloneQuickReply

Creates a quick reply from an I18nTranslator.

fun I18nTranslator.standaloneQuickReply(title: CharSequence, targetIntent: IntentAware, parameters: Parameters = Parameters(), step: StoryStep<out StoryHandlerDefinition>? = null, imageUrl: String? = null, busStep: StoryStep<out StoryHandlerDefinition>? = null, currentIntent: Intent? = null, sourceAppId: String?): QuickReply

text

Creates a text with quick replies.

fun I18nTranslator.text(text: CharSequence, vararg quickReplies: QuickReply): TextMessage
fun I18nTranslator.text(text: CharSequence, quickReplies: List<QuickReply>): TextMessage

urlButton

Creates an url button.

fun I18nTranslator.urlButton(title: CharSequence, url: String): UrlButton

video

Creates a video as attachment (https://developers.facebook.com/docs/messenger-platform/reference/send-api/#attachment).

fun <T : Bus<T>> T.video(videoUrl: String, vararg quickReplies: QuickReply): AttachmentMessage
fun <T : Bus<T>> T.video(videoUrl: String, quickReplies: List<QuickReply>): AttachmentMessage

withMessenger

Adds a Messenger ConnectorMessage if the current connector is Messenger. You need to call T:BusT.send or T:BusT.end later to send this message.

fun <T : Bus<T>> T.withMessenger(messageProvider: () -> MessengerConnectorMessage): T

Adds a Messenger ConnectorMessage if the current connector is Messenger and the current connector is connectorId. You need to call T:BusT.send or T:BusT.end later to send this message.

fun <T : Bus<T>> T.withMessenger(connectorId: String, messageProvider: () -> MessengerConnectorMessage): T