Skip to content

Commit

Permalink
add function notify for whatsapp cloud connector
Browse files Browse the repository at this point in the history
  • Loading branch information
BENKACI Amira authored and vsct-jburet committed Sep 30, 2024
1 parent 91ef37d commit 9ef7b3b
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 2 deletions.
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

0 comments on commit 9ef7b3b

Please sign in to comment.