> ## Documentation Index
> Fetch the complete documentation index at: https://autclaw.shop/llms.txt
> Use this file to discover all available pages before exploring further.

# Python Sender message capabilities

> Use Python Sender to read user and chat information, reply with text, Markdown, media, and mixed messages, and recall messages.

`Sender` binds to the current runtime context. For message triggers, it represents the current IM, account, chat, and user. For route triggers, it represents the current HTTP request. Cron / fake contexts may not point to a real IM chat.

```python theme={null}
from middleware import Sender, getSenderID

sender = Sender(getSenderID())
```

## Read message context

These methods take no arguments and return fields from the current runtime context. Missing fields usually return an empty string, empty array, or `False`.

| Method                         | Purpose                                                                           | Parameters                                                   | Returns     |
| ------------------------------ | --------------------------------------------------------------------------------- | ------------------------------------------------------------ | ----------- |
| `getImtype()`                  | Get the current IM type. Cron runs may return `fake`.                             | None                                                         | `str`       |
| `getUserID()`                  | Get the current user ID.                                                          | None                                                         | `str`       |
| `getUserName()`                | Get the current user display name.                                                | None                                                         | `str`       |
| `getUserAvatarUrl()`           | Get the current user avatar URL.                                                  | None                                                         | `str`       |
| `getChatID()`                  | Get the current chat ID; group chats use group ID, private chats are often empty. | None                                                         | `str`       |
| `getChatName()`                | Get the current chat name.                                                        | None                                                         | `str`       |
| `getGroupName()`               | Get the group name. Same as `getChatName()`.                                      | None                                                         | `str`       |
| `isAdmin()`                    | Check whether the current user is an administrator.                               | None                                                         | `bool`      |
| `isAI()`                       | Check whether the message came from an AI trigger context.                        | None                                                         | `bool`      |
| `getAIParam()`                 | Get the AI parameter.                                                             | None                                                         | `str`       |
| `getMessage()`                 | Get the current message text.                                                     | None                                                         | `str`       |
| `getMessageID()`               | Get the current message ID.                                                       | None                                                         | `str`       |
| `getHistoryMessageIDs(number)` | Get recent message IDs.                                                           | `number`: required count.                                    | `list[str]` |
| `param(index)`                 | Read a `rule` regex capture.                                                      | `index` starts at `1`; out-of-range returns an empty string. | `str`       |

```python theme={null}
user = sender.getUserName()
message = sender.getMessage()
first_match = sender.param(1)
sender.reply(f"{user} sent: {message}\nParam: {first_match}")
```

## Reply with text and media

`reply*` methods reply to the current runtime context. For message triggers, they reply to the current chat. For route triggers, `reply(...)` / `replyMarkdown(...)` can write the route response. A cron `fake` context does not send a real IM reply.

| Method                             | Purpose                                                     | Parameters                                                | Returns        |
| ---------------------------------- | ----------------------------------------------------------- | --------------------------------------------------------- | -------------- |
| `reply(text)`                      | Reply with plain text.                                      | `text`: required.                                         | `SendReceipt`  |
| `replyMarkdown(markdown)`          | Reply with Markdown text. Rendering depends on the adapter. | `markdown`: required.                                     | `SendReceipt`  |
| `replyImage(source, options=None)` | Reply with an image.                                        | Image URL, path, base64, or data URI; `options` optional. | `SendReceipt`  |
| `replyVoice(source, options=None)` | Reply with voice/audio.                                     | Voice URL or path; `options` optional.                    | `SendReceipt`  |
| `replyVideo(source, options=None)` | Reply with a video.                                         | Video URL or path; `options` optional.                    | `SendReceipt`  |
| `replyFile(source, options=None)`  | Reply with a file.                                          | File URL or path; `options` optional.                     | `SendReceipt`  |
| `replyMixed(items, options=None)`  | Reply with structured mixed messages.                       | `items`: required mixed items.                            | `SendReceipt`  |
| `returnValue(text)`                | Set the runtime return value without sending an IM message. | `text`: required.                                         | Runtime result |

```python theme={null}
sender.reply("Plain text")
sender.replyMarkdown("## Result\n\n- Done")
sender.replyImage("https://example.com/a.png")
sender.replyVoice("./voice.wav")
sender.replyVideo("./demo.mp4")
sender.replyFile("./report.csv", {"filename": "report.csv", "mimeType": "text/csv"})
sender.replyMixed([
    {"type": "text", "text": "Result: "},
    {"type": "image", "source": "./result.png", "name": "result.png"},
])
```

<Note>
  `replyImage(...)` and other current-chat reply methods do not need `imType`, group ID, or user ID. Use [`push(...)`](/en/plugin-sdk/python/push) or `push*` when you need to choose the target.
</Note>

## MediaOptions

Media reply methods accept an optional dictionary as the second parameter.

<ParamField path="options.filename" type="string">
  Display filename. Also accepted as `fileName` or `file_name`.
</ParamField>

<ParamField path="options.mimeType" type="string">
  MIME type. Also accepted as `mime_type`.
</ParamField>

<ParamField path="options.timeout" type="number">
  Media request timeout. Millisecond values are converted to request timeout.
</ParamField>

## Control flow

| Method                     | Purpose                                      | Parameters               | Returns        |
| -------------------------- | -------------------------------------------- | ------------------------ | -------------- |
| `setContinue()`            | Continue matching subsequent plugins.        | None                     | `bool`         |
| `recallMessage(messageid)` | Recall a message.                            | `messageid`: message ID. | `SendReceipt`  |
| `breakIn(content)`         | Re-enter the message pipeline with new text. | `content`: required.     | Runtime result |

```python theme={null}
if sender.isAdmin():
    sender.setContinue()
else:
    sender.reply("Only administrators can continue.")
```

## Next steps

* Wait for user input: [`Wait for input and payment`](/en/plugin-sdk/python/wait-and-payment)
* Download media and read event fields: [`Events, media, and files`](/en/plugin-sdk/python/media-files)
