open override fun process(scope: PipelineScope, span: PerformanceSpan) Samples
import ai.flowstorm.common.monitoring.performance.PerformanceSpan
import ai.flowstorm.core.Context
import ai.flowstorm.core.Response
import ai.flowstorm.core.Scope
import ai.flowstorm.core.model.Turn
import ai.flowstorm.core.nlp.pipeline.PipelineComponent
import ai.flowstorm.core.nlp.pipeline.PipelineScope
import ai.flowstorm.core.type.DateTime
import ai.flowstorm.core.type.IntMutableList
fun main() {
//sampleStart
with(scope.context) {
scopeAttributes = ScopeAttributes(scope)
logger.info("Processing built-in analytics...")
with(scopeAttributes) {
addFlow(scope.context)
detectedSentiment = input.sentiment.name
if (input.action == null || input.action == "outofdomain") {
when (voiceOrText) {
"" -> voiceOrText = if (input.transcript.confidence == 1.0F) "TEXT" else "VOICE"
"TEXT" -> voiceOrText = if (input.transcript.confidence != 1.0F) "BOTH" else "TEXT"
else -> voiceOrText = if (input.transcript.confidence == 1.0F) "BOTH" else "VOICE"
}
}
talkToPoppy_application = true
saveAntecedentResponses(scope.context)
if (input.action == null || input.action == "outofdomain") {
var timeBeforeIncrementation = sessionDurationInSeconds
sessionDurationInSeconds = (DateTime.now(turn.input.zoneId).toInstant().epochSecond - openTimestamp.toInstant().epochSecond)
var currentIncrement = (sessionDurationInSeconds - timeBeforeIncrementation)
if (currentIncrement > 600)
currentIncrement = 0L
totalConversationTime += currentIncrement
if (userAppSessionsDuration.isEmpty()) {
userAppSessionsDuration.add(0)
userAppSessionCounter = userAppSessionsDuration.size
logger.info("a new element was added to userAppSessionsDuration list")
}
var lastAppSessionDurationBeforeIncrementation = userAppSessionsDuration.last()
userAppSessionsDuration.removeLast()
userAppSessionsDuration.add(lastAppSessionDurationBeforeIncrementation + currentIncrement.toInt())
userAppSessionsDurationAverage = userAppSessionsDuration.average().toInt()
var previousTurns = 0
achievementTurnsTotal++
turnCounter++
totalTurns++
if (isIn_socialTalk_activity)
socialTalk_activity_turns++
if (poppysPlaces_turnsFromUser > 0)
poppysPlaces_turnsFromUser++
if (poppysPlaces_turnsInSession > 0)
poppysPlaces_turnsInSession++
if (turnCounter == 5) {
userSessionCounter++
if (userSessionCounter == 1)
lastVisitTime = DateTime.now(turn.input.zoneId)
if (userSessionCounter >= 2 && DateTime.now(turn.input.zoneId).minusHours(10) >= lastVisitTime) {
lastVisitTime = DateTime.now(turn.input.zoneId)
userReturns++
}
logger.info("event significant_session emitted")
scope.addResponseItem(Response.Item("#event", code = """{"name": "significant_session","properties": []}""", repeatable = false))
logger.info("command rating emitted")
scope.addResponseItem(Response.Item("#rating", repeatable = false))
if (testingRun && achievementVoiceOnly_points == 4 && !achievementVoiceOnly_done) {
achievementVoiceOnly_done = true
}
}
}
scope.addResponseItem(Response.Item(text = "#beepOn", code = "{\"on\": false}", repeatable = false))
}
}
//sampleEnd
}