Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add function notify for whatsapp cloud connector #1728

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ fun I18nTranslator.whatsAppCloudListMessage(
): WhatsAppCloudBotInteractiveMessage =
whatsAppCloudListMessage(text, button, replies.toList())


fun I18nTranslator.whatsAppCloudListMessage(
text: CharSequence,
button: CharSequence,
Expand All @@ -174,6 +175,7 @@ fun I18nTranslator.whatsAppCloudListMessage(
WhatsAppBotRow(
id = it.payload,
title = it.title,
description = it.description
)
})
)
Expand Down Expand Up @@ -263,6 +265,17 @@ fun <T : Bus<T>> T.whatsAppCloudQuickReply(
SendChoice.encodeChoiceId(intent, s, params, null, null, sourceAppId = null)
}

fun <T : Bus<T>> T.whatsAppCloudQuickReply(
title: CharSequence,
subTitle: CharSequence? = null,
targetIntent: IntentAware,
step: String? = null,
parameters: Map<String, String> = mapOf()
): QuickReply =
whatsAppCloudQuickReply(title,subTitle, targetIntent, step, parameters) { intent, s, params ->
SendChoice.encodeChoiceId(intent, s, params, null, null, sourceAppId = null)
}

private fun I18nTranslator.whatsAppCloudQuickReply(
title: CharSequence,
targetIntent: IntentAware,
Expand All @@ -274,6 +287,19 @@ private fun I18nTranslator.whatsAppCloudQuickReply(
payloadEncoder.invoke(targetIntent, step, parameters)
)

private fun I18nTranslator.whatsAppCloudQuickReply(
title: CharSequence,
subTitle: CharSequence? = null,
targetIntent: IntentAware,
step: String? = null,
parameters: Map<String, String>,
payloadEncoder: (IntentAware, String?, Map<String, String>) -> String
): QuickReply = QuickReply(
translate(title).toString(),
payloadEncoder.invoke(targetIntent, step, parameters),
translate(subTitle).toString()
)

fun I18nTranslator.whatsAppCloudNlpQuickReply(
title: CharSequence,
textToSend: CharSequence = title,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package ai.tock.bot.connector.whatsapp.cloud

import ai.tock.bot.connector.ConnectorCallbackBase
import ai.tock.bot.connector.ConnectorType
import ai.tock.bot.engine.action.ActionNotificationType

class WhatsAppConnectorCloudCallback (
applicationId: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,19 @@ import ai.tock.bot.connector.whatsapp.cloud.model.webhook.WebHookEventReceiveMes
import ai.tock.bot.connector.whatsapp.cloud.model.webhook.message.WhatsAppCloudMessage
import ai.tock.bot.connector.whatsapp.cloud.services.SendActionConverter
import ai.tock.bot.connector.whatsapp.cloud.services.WhatsAppCloudApiService
import ai.tock.bot.definition.IntentAware
import ai.tock.bot.definition.StoryHandlerDefinition
import ai.tock.bot.definition.StoryStep
import ai.tock.bot.engine.BotRepository
import ai.tock.bot.engine.ConnectorController
import ai.tock.bot.engine.action.Action
import ai.tock.bot.engine.action.ActionNotificationType
import ai.tock.bot.engine.action.SendChoice
import ai.tock.bot.engine.event.Event
import ai.tock.bot.engine.monitoring.logError
import ai.tock.bot.engine.user.PlayerId
import ai.tock.bot.engine.user.PlayerType
import ai.tock.bot.engine.user.PlayerType.bot
import ai.tock.shared.*
import ai.tock.shared.jackson.mapper
import ai.tock.shared.security.RequestFilter
Expand Down Expand Up @@ -178,4 +186,29 @@ class WhatsAppConnectorCloudConnector internal constructor(
}
}
}

override fun notify(
controller: ConnectorController,
recipientId: PlayerId,
intent: IntentAware,
step: StoryStep<out StoryHandlerDefinition>?,
parameters: Map<String, String>,
notificationType: ActionNotificationType?,
errorListener: (Throwable) -> Unit
) {
controller.handle(

SendChoice(
recipientId,
connectorId,
PlayerId(connectorId, bot),
intent.wrappedIntent().name,
step,
parameters
),
ConnectorData(
WhatsAppConnectorCloudCallback(connectorId)
)
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@

package ai.tock.bot.connector.whatsapp.cloud.model.send

data class QuickReply(val title: String, val payload: String)
data class QuickReply(val title: String, val payload: String, val description:String? = null)
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ data class WhatsAppCloudBotActionSection(
data class WhatsAppBotRow(
val id: String,
val title: String,
val description: String? = null,
val description: CharSequence? = null,
) {
fun toChoice() : Choice =
SendChoice.decodeChoiceId(id)
Expand Down