在继续之前要求用户执行一个操作。如果用户未在规定时间内(参见 timeout)回复,将根据 raise_on_timeout 参数抛出 TimeoutError 异常或返回 None。如果配置了项目 ID,消息将上传到云存储。

属性

content
str

消息内容。

actions
List[Action]

提示用户的 操作 列表。

author
str

消息的作者,默认为您配置中定义的聊天机器人名称。

timeout
int
默认:90

等待回复的秒数,超时将抛出 TimeoutError。

raise_on_timeout
bool
默认:"False"

如果用户未在规定时间内回复,是否抛出 socketio TimeoutError。

返回值

response
AskActionResponse | None
必填

用户的回复。

示例

import chainlit as cl


@cl.on_chat_start
async def main():
    res = await cl.AskActionMessage(
        content="Pick an action!",
        actions=[
            cl.Action(name="continue", payload={"value": "continue"}, label="✅ Continue"),
            cl.Action(name="cancel", payload={"value": "cancel"}, label="❌ Cancel"),
        ],
    ).send()

    if res and res.get("payload").get("value") == "continue":
        await cl.Message(
            content="Continue!",
        ).send()