> ## Documentation Index
> Fetch the complete documentation index at: https://docs.camel-ai.org/llms.txt
> Use this file to discover all available pages before exploring further.

# Camel.toolkits.wechat official toolkit

<a id="camel.toolkits.wechat_official_toolkit" />

<a id="camel.toolkits.wechat_official_toolkit._get_wechat_access_token" />

## \_get\_wechat\_access\_token

```python theme={"system"}
def _get_wechat_access_token():
```

**Returns:**

str: The valid access token.

**Raises:**

* **ValueError**: If credentials are missing or token retrieval fails.
* **References**:
* **https**: //developers.weixin.qq.com/doc/offiaccount/Basic\_Information/Get\_access\_token.html

<a id="camel.toolkits.wechat_official_toolkit._make_wechat_request" />

## \_make\_wechat\_request

```python theme={"system"}
def _make_wechat_request(method: Literal['GET', 'POST'], endpoint: str, **kwargs):
```

Makes a request to WeChat API with proper error handling.

**Parameters:**

* **method** (`Literal["GET", "POST"]`): HTTP method ('GET' or 'POST').
* **endpoint** (str): API endpoint path. \*\*kwargs: Additional arguments for requests.

**Returns:**

Dict\[str, Any]: API response data.

**Raises:**

* **requests.exceptions.RequestException**: If request fails.
* **ValueError**: If API returns an error.

<a id="camel.toolkits.wechat_official_toolkit.WeChatOfficialToolkit" />

## WeChatOfficialToolkit

```python theme={"system"}
class WeChatOfficialToolkit(BaseToolkit):
```

A toolkit for WeChat Official Account operations.

This toolkit provides methods to interact with the WeChat Official Account
API, allowing users to send messages, manage users, and handle media files.

References:

* Documentation: [https://developers.weixin.qq.com/doc/offiaccount/Getting\_Started/Overview.html](https://developers.weixin.qq.com/doc/offiaccount/Getting_Started/Overview.html)
* Test Account: [https://mp.weixin.qq.com/debug/cgi-bin/sandbox?t=sandbox/login](https://mp.weixin.qq.com/debug/cgi-bin/sandbox?t=sandbox/login)

**Note:**

Set environment variables: WECHAT\_APP\_ID, WECHAT\_APP\_SECRET

<a id="camel.toolkits.wechat_official_toolkit.WeChatOfficialToolkit.__init__" />

### **init**

```python theme={"system"}
def __init__(self, timeout: Optional[float] = None):
```

Initializes the WeChatOfficialToolkit.

<a id="camel.toolkits.wechat_official_toolkit.WeChatOfficialToolkit.send_customer_message" />

### send\_customer\_message

```python theme={"system"}
def send_customer_message(
    self,
    openid: str,
    content: str,
    msgtype: Literal['text', 'image', 'voice', 'video'] = 'text'
):
```

Sends a customer service message to a WeChat user.

**Parameters:**

* **openid** (str): The user's OpenID.
* **content** (str): Message content or media\_id for non-text messages.
* **msgtype** (str): Message type: "text", "image", "voice", "video".

**Returns:**

str: Success or error message.

References:
[https://developers.weixin.qq.com/doc/offiaccount/Message\_Management/Service\_Center\_messages.html](https://developers.weixin.qq.com/doc/offiaccount/Message_Management/Service_Center_messages.html)

<a id="camel.toolkits.wechat_official_toolkit.WeChatOfficialToolkit.get_user_info" />

### get\_user\_info

```python theme={"system"}
def get_user_info(self, openid: str, lang: str = 'zh_CN'):
```

Retrieves WeChat user information.

**Parameters:**

* **openid** (str): The user's OpenID.
* **lang** (str): Response language. Common values: "zh\_CN", "zh\_TW", "en". (default: "zh\_CN")

**Returns:**

Dict\[str, Any]: User information as dictionary or error
information.

References:
[https://developers.weixin.qq.com/doc/offiaccount/User\_Management/](https://developers.weixin.qq.com/doc/offiaccount/User_Management/)
Getting\_user\_basic\_information.html

<a id="camel.toolkits.wechat_official_toolkit.WeChatOfficialToolkit.get_followers_list" />

### get\_followers\_list

```python theme={"system"}
def get_followers_list(self, next_openid: str = ''):
```

Retrieves list of followers' OpenIDs.

**Parameters:**

* **next\_openid** (str): Starting OpenID for pagination. (default: "") (default: `""`)

**Returns:**

Dict\[str, Any]: Followers list as dictionary or error information.

References:
[https://developers.weixin.qq.com/doc/offiaccount/User\_Management/](https://developers.weixin.qq.com/doc/offiaccount/User_Management/)
Getting\_a\_list\_of\_followers.html

<a id="camel.toolkits.wechat_official_toolkit.WeChatOfficialToolkit.upload_wechat_media" />

### upload\_wechat\_media

```python theme={"system"}
def upload_wechat_media(
    self,
    media_type: Literal['image', 'voice', 'video', 'thumb'],
    file_path: str,
    permanent: bool = False,
    description: Optional[str] = None
):
```

Uploads media file to WeChat.

**Parameters:**

* **media\_type** (str): Media type: "image", "voice", "video", "thumb".
* **file\_path** (str): Local file path.
* **permanent** (bool): Whether to upload as permanent media. (default: :obj:`False`)
* **description** (Optional\[str]): Video description in JSON format for permanent upload. (default: :obj:`None`)

**Returns:**

Dict\[str, Any]: Upload result with media\_id or error information.

References:

* Temporary: [https://developers.weixin.qq.com/doc/offiaccount/](https://developers.weixin.qq.com/doc/offiaccount/)
  Asset\_Management/Adding\_Temporary\_Assets.html
* Permanent: [https://developers.weixin.qq.com/doc/offiaccount/](https://developers.weixin.qq.com/doc/offiaccount/)
  Asset\_Management/Adding\_Permanent\_Assets.html

<a id="camel.toolkits.wechat_official_toolkit.WeChatOfficialToolkit.get_media_list" />

### get\_media\_list

```python theme={"system"}
def get_media_list(
    self,
    media_type: Literal['image', 'voice', 'video', 'news'],
    offset: int = 0,
    count: int = 20
):
```

Gets list of permanent media files.

**Parameters:**

* **media\_type** (str): Media type: "image", "voice", "video", "news".
* **offset** (int): Starting position. (default: :obj:`0`) (default: 0)
* **count** (int): Number of items (1-20). (default: :obj:`20`) (default: 20)

**Returns:**

Dict\[str, Any]: Media list as dictionary or error information.

References:
[https://developers.weixin.qq.com/doc/offiaccount/Asset\_Management/](https://developers.weixin.qq.com/doc/offiaccount/Asset_Management/)
Get\_the\_list\_of\_all\_materials.html

<a id="camel.toolkits.wechat_official_toolkit.WeChatOfficialToolkit.send_mass_message_to_all" />

### send\_mass\_message\_to\_all

```python theme={"system"}
def send_mass_message_to_all(
    self,
    content: str,
    msgtype: Literal['text', 'image', 'voice', 'video'] = 'text',
    clientmsgid: Optional[str] = None,
    send_ignore_reprint: Optional[int] = 0,
    batch_size: int = 10000
):
```

Sends a mass message to all followers (by OpenID list).

This method paginates all follower OpenIDs and calls the
mass-send API in batches.

**Parameters:**

* **content** (str): For text, the message content; for non-text, the media\_id.
* **msgtype** (`Literal["text","image","voice","video"]`): Message type. For "video", the mass API expects "mpvideo" internally.
* **clientmsgid** (Optional\[str]): Idempotency key to avoid duplicate mass jobs.
* **send\_ignore\_reprint** (Optional\[int]): Whether to continue when a news article is judged as a reprint (reserved; applies to news/mpnews).
* **batch\_size** (int): Max OpenIDs per request (WeChat limit is up to 10000 per batch).

**Returns:**

Dict\[str, Any]: Aggregated result including counts and
each batch response.

References:

* Mass send by OpenID list:
  [https://developers.weixin.qq.com/doc/service/api/notify/message/](https://developers.weixin.qq.com/doc/service/api/notify/message/)
  api\_masssend.html

<a id="camel.toolkits.wechat_official_toolkit.WeChatOfficialToolkit.get_tools" />

### get\_tools

```python theme={"system"}
def get_tools(self):
```

Returns toolkit functions as tools.
