Back to Bolt Python

slack_bolt.context.assistant.assistant_utilities API documentation

docs/reference/context/assistant/assistant_utilities.html

1.28.05.2 KB
Original Source

Classes

class AssistantUtilities (*,payload: dict,context: BoltContext,thread_context_store: AssistantThreadContextStore | None = None)#Expand source code

class AssistantUtilities:
    payload: dict
    client: WebClient
    channel_id: str
    thread_ts: str
    thread_context_store: AssistantThreadContextStore

    def __init__ (
        self,
        *,
        payload: dict,
        context: BoltContext,
        thread_context_store: Optional[AssistantThreadContextStore] = None,
    ):
        self.payload = payload
        self.client = context.client
        self.thread_context_store = thread_context_store or DefaultAssistantThreadContextStore(context)

        if has_channel_id_and_thread_ts(self.payload):
            # assistant_thread_started
            thread = self.payload["assistant_thread"]
            self.channel_id = thread["channel_id"]
            self.thread_ts = thread["thread_ts"]
        elif self.payload.get("channel") is not None and self.payload.get("thread_ts") is not None:
            # message event
            self.channel_id = self.payload["channel"]
            self.thread_ts = self.payload["thread_ts"]
        else:
            # When moving this code to Bolt internals, no need to raise an exception for this pattern
            raise ValueError(f"Cannot instantiate Assistant for this event pattern ({self.payload})")

    def is_valid(self) -> bool:
        return self.channel_id is not None and self.thread_ts is not None

    @property
    def set_status(self) -> SetStatus:
        warnings.warn(
            "AssistantUtilities.set_status is deprecated. "
            "Use the set_status argument directly in your listener function "
            "or access it via context.set_status instead.",
            DeprecationWarning,
            stacklevel=2,
        )
        return SetStatus(self.client, self.channel_id, self.thread_ts)

    @property
    def set_title(self) -> SetTitle:
        return SetTitle(self.client, self.channel_id, self.thread_ts)

    @property
    def set_suggested_prompts(self) -> SetSuggestedPrompts:
        return SetSuggestedPrompts(self.client, self.channel_id, self.thread_ts)

    @property
    def say(self) -> Say:
        def build_metadata() -> Optional[dict]:
            thread_context = self.get_thread_context()
            if thread_context is not None:
                return {"event_type": "assistant_thread_context", "event_payload": thread_context}
            return None

        return Say(
            self.client,
            channel=self.channel_id,
            thread_ts=self.thread_ts,
            build_metadata=build_metadata,
        )

    @property
    def get_thread_context(self) -> GetThreadContext:
        return GetThreadContext(self.thread_context_store, self.channel_id, self.thread_ts, self.payload)

    @property
    def save_thread_context(self) -> SaveThreadContext:
        return SaveThreadContext(self.thread_context_store, self.channel_id, self.thread_ts)

Class variables

var channel_id : str

The type of the None singleton.

var client : slack_sdk.web.client.WebClient

The type of the None singleton.

var payload : dict

The type of the None singleton.

var thread_context_store : AssistantThreadContextStore

The type of the None singleton.

var thread_ts : str

The type of the None singleton.

Instance variables

prop get_thread_context : GetThreadContext#Expand source code

@property
def get_thread_context(self) -> GetThreadContext:
    return GetThreadContext(self.thread_context_store, self.channel_id, self.thread_ts, self.payload)

prop save_thread_context : SaveThreadContext#Expand source code

@property
def save_thread_context(self) -> SaveThreadContext:
    return SaveThreadContext(self.thread_context_store, self.channel_id, self.thread_ts)

prop say : Say#Expand source code

@property
def say(self) -> Say:
    def build_metadata() -> Optional[dict]:
        thread_context = self.get_thread_context()
        if thread_context is not None:
            return {"event_type": "assistant_thread_context", "event_payload": thread_context}
        return None

    return Say(
        self.client,
        channel=self.channel_id,
        thread_ts=self.thread_ts,
        build_metadata=build_metadata,
    )

prop set_status : SetStatus#Expand source code

@property
def set_status(self) -> SetStatus:
    warnings.warn(
        "AssistantUtilities.set_status is deprecated. "
        "Use the set_status argument directly in your listener function "
        "or access it via context.set_status instead.",
        DeprecationWarning,
        stacklevel=2,
    )
    return SetStatus(self.client, self.channel_id, self.thread_ts)

prop set_suggested_prompts : SetSuggestedPrompts#Expand source code

@property
def set_suggested_prompts(self) -> SetSuggestedPrompts:
    return SetSuggestedPrompts(self.client, self.channel_id, self.thread_ts)

prop set_title : SetTitle#Expand source code

@property
def set_title(self) -> SetTitle:
    return SetTitle(self.client, self.channel_id, self.thread_ts)

Methods

def is_valid(self) ‑> bool#Expand source code

def is_valid(self) -> bool:
    return self.channel_id is not None and self.thread_ts is not None