nonebot2/archive/2.0.0a8.post2/api/adapters/ding.md
2021-01-02 18:04:44 +08:00

4.5 KiB
Raw Blame History

contentSidebar sidebarDepth
true 0

NoneBot.adapters.ding 模块

钉钉群机器人 协议适配

协议详情请看: 钉钉文档

NoneBot.adapters.ding.exception 模块

exception DingAdapterException

基类:nonebot.exception.AdapterException

  • 说明

    钉钉 Adapter 错误基类

exception ActionFailed

基类:nonebot.exception.ActionFailed, nonebot.adapters.ding.exception.DingAdapterException

  • 说明

    API 请求返回错误信息。

  • 参数

    • errcode: Optional[int]: 错误码

    • errmsg: Optional[str]: 错误信息

exception NetworkError

基类:nonebot.exception.NetworkError, nonebot.adapters.ding.exception.DingAdapterException

  • 说明

    网络错误。

  • 参数

    • retcode: Optional[int]: 错误码

exception SessionExpired

基类:nonebot.adapters.ding.exception.ApiNotAvailable, nonebot.adapters.ding.exception.DingAdapterException

  • 说明

    发消息的 session 已经过期。

NoneBot.adapters.ding.bot 模块

class Bot

基类:nonebot.adapters.Bot

钉钉 协议 Bot 适配。继承属性参考 BaseBot

property type

  • 返回: "ding"

async classmethod check_permission(driver, connection_type, headers, body)

  • 说明

    钉钉协议鉴权。参考 鉴权

async call_api(api, event=None, **data)

  • 说明

    调用 钉钉 协议 API

  • 参数

    • api: str: API 名称

    • **data: Any: API 参数

  • 返回

    • Any: API 调用返回数据
  • 异常

    • NetworkError: 网络错误

    • ActionFailed: API 调用失败

async send(event, message, at_sender=False, **kwargs)

  • 说明

    根据 event 向触发事件的主体发送消息。

  • 参数

    • event: Event: Event 对象

    • message: Union[str, Message, MessageSegment]: 要发送的消息

    • at_sender: bool: 是否 @ 事件主体

    • **kwargs: 覆盖默认参数

  • 返回

    • Any: API 调用返回数据
  • 异常

    • ValueError: 缺少 user_id, group_id

    • NetworkError: 网络错误

    • ActionFailed: API 调用失败

NoneBot.adapters.ding.message 模块

class MessageSegment

基类:nonebot.adapters.MessageSegment

钉钉 协议 MessageSegment 适配。具体方法参考协议消息段类型或源码。

static atAll()

@全体

static atMobiles(*mobileNumber)

@指定手机号人员

static text(text)

发送 text 类型消息

static image(picURL)

发送 image 类型消息

static extension(dict_)

"标记 text 文本的 extension 属性,需要与 text 消息段相加。

static markdown(title, text)

发送 markdown 类型消息

static actionCardSingleBtn(title, text, singleTitle, singleURL)

发送 actionCardSingleBtn 类型消息

static actionCardMultiBtns(title, text, btns, hideAvatar=False, btnOrientation='1')

发送 actionCardMultiBtn 类型消息

  • 参数

    • btnOrientation: 0按钮竖直排列 1按钮横向排列

    • btns: [{ "title": title, "actionURL": actionURL }, ...]

发送 feedCard 类型消息

  • 参数

    • links: [{ "title": xxx, "messageURL": xxx, "picURL": xxx }, ...]

class Message

基类:nonebot.adapters.Message

钉钉 协议 Message 适配。

NoneBot.adapters.ding.event 模块

class Event

基类:nonebot.adapters.Event

钉钉协议事件。各事件字段参考 钉钉文档

class ConversationType

基类:str, enum.Enum

An enumeration.

class MessageEvent

基类:nonebot.adapters.ding.event.Event

消息事件

class PrivateMessageEvent

基类:nonebot.adapters.ding.event.MessageEvent

私聊消息事件

class GroupMessageEvent

基类:nonebot.adapters.ding.event.MessageEvent

群消息事件