Skip to content

context

Dmitriy Chechyotkin edited this page Mar 16, 2020 · 5 revisions

BotContext instance is available through context in the action block. It can be used by scenario to store temp-, session- and client-scoped arbitrary data, related to the current user.

JAICF transparently manages the state of BotContext storing and fetching it for each user's request using managers.

Learn more about managers here.

state("name") {
    action {
        context.client["name"] = context.result
        reactions.say("Nice to meet you ${context.result}")
   }
}

Here the value from context.result is saved to the client-scoped data map in the context. On the next request from the same user JAICF will fetch their context and "name" variable will be available via context.client["name"].

Client scope

Client scoped map persists values permanently and available through context.client.

Session scope

Session scoped map persists values for the current session. It is up to the channel to start a new session and clean this map. It is available through context.session.

Temp scope

Temp scoped map persists values only during the current request processing. This is a way to pass values over different hops between dialogue states. It is available through context.temp.

Result

result variable may contain arbitrary data passed back to the callback state.

state("main") {
    action {
        reactions.go("/helper/ask4name", "name")
    }
}

state("name") {
    action {
        reactions.say("Nice to meet you ${context.result}!")
    }
}
Clone this wiki locally