AI Knowledge & Logic

Python Context

The context object passed to every Python function — conversation data, customer profile, business info, and more.

Every Python function in Octocom — whether it's a custom action, condition provider, event handler, or sidebar widget — receives a single context dictionary as its argument. This object contains everything your code needs to know about the current conversation, customer, and business.


Top-level fields

FieldTypeDescription
conversationdict or NoneThe current conversation — messages, IDs, subject, and channel info
businessdictThe business this conversation belongs to
customerdict or NoneThe customer's profile — None if the customer hasn't been identified
argsdictArguments passed to the function (custom actions, condition providers, and event handlers)
browser_sessiondict or NoneBrowser session data — only present for web chat conversations

context["conversation"]

Contains the full conversation with its messages. Always present for event handlers and sidebar widgets. Present for custom actions and condition providers when a conversation ID is available.

FieldTypeDescription
idstrInternal conversation UUID
publicIdstrShort public ID shown in the dashboard (e.g., "A1B2C3")
subjectstrConversation subject line
businessSlugstrSlug of the business this conversation belongs to
initialChannelstr or NoneChannel of the first message (e.g., "web", "email", "instagram")
latestChannelstr or NoneChannel of the most recent message
messageslistArray of message objects (see below)

Messages

Each entry in context["conversation"]["messages"] is a dictionary:

FieldTypeDescription
senderstrWho sent the message — "customer", "bot", or "agent"
timestampstrWhen the message was sent (ISO 8601 format)
contentstrThe message text
channelstrThe channel the message was sent on

context["business"]

Basic information about the business.

FieldTypeDescription
namestrThe business name
slugstrThe business slug

context["customer"]

The customer's profile. This is None if the customer hasn't been identified yet (e.g., the conversation just started and no email has been collected).

FieldTypeDescription
idstrInternal customer UUID
emailstr or NoneCustomer email address
namestr or NoneCustomer name
phonestr or NoneCustomer phone number
instagramUsernamestr or NoneCustomer's Instagram handle

context["args"]

A dictionary of arguments passed to the function. The contents depend on the function type:

  • Custom actions — arguments defined in the action configuration and provided by the bot (e.g., context["args"]["orderId"])
  • Condition providers — arguments defined in the workflow configuration and collected from the customer (e.g., context["args"]["email"])
  • Event handlers — contains a single event_type key with the event name (e.g., context["args"]["event_type"] returns "conversation_closed")
  • Sidebar widgets — do not receive args

context["browser_session"]

Browser session data for web chat conversations. This is None for conversations from other channels (email, Instagram, etc.). Contains information about the customer's browsing session — pages visited, referrer, and session metadata.


Availability by function type

Not every field is present in every function type:

FieldCustom ActionsCondition ProvidersEvent HandlersSidebar Widgets
conversationIf availableIf availableAlwaysAlways
businessAlwaysAlwaysAlwaysAlways
customerIf availableIf availableIf availableIf available
argsAlwaysAlwaysAlwaysNot present
browser_sessionWeb chat onlyWeb chat onlyWeb chat onlyWeb chat only

On this page