开发者社区> 问答> 正文

钉钉如何在outgoing过程中发送卡片?

钉钉如何在outgoing过程中发送卡片?

展开
收起
2401。 2023-07-17 12:47:15 46 0
2 条回答
写回答
取消 提交回答
  • 北京阿里云ACE会长

    具体步骤如下:

    准备发送消息的数据,包括消息标题、消息内容、按钮名称、按钮链接等信息。例如:
    json
    Copy
    {
    "msgtype": "actionCard",
    "actionCard": {
    "title": "这是一条整体跳转的卡片消息",
    "text": "点击下方按钮跳转至相关页面",
    "singleTitle": "去相关页面",
    "singleURL": "https://www.example.com"
    }
    }
    在上述代码中,将 msgtype 设置为 actionCard,表示发送 ActionCard 样式的卡片消息。设置卡片消息的标题为 "这是一条整体跳转的卡片消息",消息内容为 "点击下方按钮跳转至相关页面",按钮名称为 "去相关页面",按钮链接为 "https://www.example.com"。

    在 Outgoing 机器人的 Webhook 地址后面添加 access_token 参数,将其设置为 Outgoing 机器人的 access_token 值。例如:
    Copy
    https://oapi.dingtalk.com/robot/send?access_token=xxxxxxxxxxxxxx
    在上述代码中,将 access_token 参数设置为 Outgoing 机器人的 access_token 值,用于验证发送者身份。

    使用 HTTP POST 请求方式,发送卡片消息。例如:
    http
    Copy
    POST https://oapi.dingtalk.com/robot/send?access_token=xxxxxxxxxxxxxx HTTP/1.1
    Content-Type: application/json

    {
    "msgtype": "actionCard",
    "actionCard": {
    "title": "这是一条整体跳转的卡片消息",
    "text": "点击下方按钮跳转至相关页面",
    "singleTitle": "去相关页面",
    "singleURL": "https://www.example.com"
    }
    }
    在上述代码中,将请求的 URL 设置为 Outgoing 机器人的 Webhook 地址,将请求的内容设置为卡片消息的数据,使用 HTTP POST 请求方式发送消息。

    2023-07-29 11:16:58
    赞同 展开评论 打赏
  • 在钉钉的outgoing过程中发送卡片消息,您可以使用Outgoing机器人API来实现。以下是一个示例的请求参数和代码示例:

    请求参数:

    {
        "msgtype": "actionCard",
        "actionCard": {
            "title": "这是标题",
            "text": "这是正文",
            "singleTitle": "查看详情",
            "singleURL": "https://example.com"
        }
    }
    

    代码示例(Python):

    import requests
    import json
    
    webhook_url = 'https://oapi.dingtalk.com/outgoing/webhooks/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    
    # 构造请求参数
    headers = {'Content-Type': 'application/json;charset=utf-8'}
    data = {
        "msgtype": "actionCard",
        "actionCard": {
            "title": "这是标题",
            "text": "这是正文",
            "singleTitle": "查看详情",
            "singleURL": "https://example.com"
        }
    }
    
    # 发送POST请求
    response = requests.post(webhook_url, headers=headers, data=json.dumps(data))
    print(response.text)
    

    请确保替换 webhook_url 为您自己的Outgoing机器人的 Webhook URL,并根据您的需求调整标题、正文和跳转链接等内容。

    2023-07-17 12:52:20
    赞同 展开评论 打赏
来源圈子
更多
收录在圈子:
+ 订阅
问答排行榜
最热
最新

相关电子书

更多
钉钉小程序——为工作方式插上翅膀 立即下载
钉钉客户端自动化的应用 立即下载
使命必达 —— 钉钉企业级 消息服务的机遇与挑战 立即下载