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)
workflowdictThe workflow being evaluated — only present when the bot runs a condition provider
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")
urlstrDirect link to this conversation in the Octocom dashboard
subjectstrConversation subject line
businessSlugstrSlug of the business this conversation belongs to
isHandedOffboolWhether the conversation has been handed off to a human agent
isPlaygroundboolWhether this is a dashboard playground conversation rather than a real customer one. Use it to relax checks that would otherwise block testing (e.g. consultant working hours)
initialChannelstr or NoneChannel of the first message (e.g., "web", "email", "instagram")
latestChannelstr or NoneChannel of the most recent message
inboxAddressstr or NoneBusiness mailbox used by the latest email thread. None for conversations without a resolvable email inbox
assigneedict or NoneThe agent currently assigned to the conversation — {"id": str, "name": str, "email": str}, or None when unassigned
tagslistTitles of the tags currently on the conversation, e.g. ["contact-form", "vip"]. Empty when untagged
metadatadictConversation metadata as {key: value}, including the chat-widget:* keys the web chat writes. Read it from here instead of calling get_conversation_metadata() when you only need current values — no HTTP round-trip
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
agentNamestr or NoneName of the agent who sent the message — set on agent-sent messages, None otherwise
agentEmailstr or NoneEmail of the agent who sent the message — set on agent-sent messages, None otherwise
fileslistFiles attached to the message (see below). Empty if none

Message files

Each entry in a message's files list is a dictionary:

FieldTypeDescription
idstrFile unique identifier
namestrOriginal filename
contentTypestrMIME type of the file (e.g., "image/jpeg", "application/pdf")
urlstrPublic URL to download the file
isSafeboolWhether the file passed malware scanning. Avoid forwarding files where this is False

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["workflow"]

Condition providers receive the workflow that caused them to run when they are evaluated by the bot:

FieldTypeDescription
idstrInternal workflow UUID
slugstrStable workflow slug
titlestrWorkflow display title

The field is absent when a condition provider is run directly as a test because no workflow triggered that execution. Use .get() when code must work in both contexts:

def evaluate_conditions(context):
    workflow = context.get("workflow")
    is_cancel_order = workflow is not None and workflow["slug"] == "cancel-order"

    return {
        "conditions": {"isCancelOrder": is_cancel_order},
        "data": {},
    }

workflow["slug"] is the recommended field for branching behavior. Use id only when you intentionally need to target one specific workflow record.


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
workflowNot presentBot execution onlyNot presentNot present
browser_sessionWeb chat onlyWeb chat onlyWeb chat onlyWeb chat only

On this page