class DingTalk::Message::ActionCard

消息类型及数据格式 - 整体跳转ActionCard类型

{
  "actionCard": {
    "title": "乔布斯 20 年前想打造一间苹果咖啡厅,而它正是 Apple Store 的前身",
    "text": "![screenshot](@lADOpwk3K80C0M0FoA)

### 乔布斯 20 年前想打造的苹果咖啡厅 Apple Store 的设计正从原来满满的科技感走向生活化,而其生活化的走向其实可以追溯到 20 年前苹果一个建立咖啡馆的计划“,

    "hideAvatar": "0",
    "btnOrientation": "0",
    "singleTitle" : "阅读全文",
    "singleURL" : "https://www.dingtalk.com/"
  },
  "msgtype": "actionCard"
}

消息类型及数据格式 - 独立跳转ActionCard类型

{
  "actionCard": {
    "title": "乔布斯 20 年前想打造一间苹果咖啡厅,而它正是 Apple Store 的前身",
    "text": "![screenshot](@lADOpwk3K80C0M0FoA)

### 乔布斯 20 年前想打造的苹果咖啡厅 Apple Store 的设计正从原来满满的科技感走向生活化,而其生活化的走向其实可以追溯到 20 年前苹果一个建立咖啡馆的计划“,

    "hideAvatar": "0",
    "btnOrientation": "0",
    "btns": [
      {
        "title": "内容不错",
        "actionURL": "https://www.dingtalk.com/"
      },
      {
        "title": "不感兴趣",
        "actionURL": "https://www.dingtalk.com/"
      }
    ]
  },
  "msgtype": "actionCard"
}

Attributes

btn_orientation[RW]
btns[RW]
hide_avatar[RW]
text[RW]
title[RW]

Public Class Methods

new(title, text, buttons, btn_orientation = '0', hide_avatar = '0') click to toggle source
# File lib/DingTalk/core/action_card.rb, line 44
def initialize(title, text, buttons, btn_orientation = '0', hide_avatar = '0')
  @title = title # 首屏会话透出的展示内容
  @text = text # markdown格式的消息
  @buttons = buttons # 按钮的信息:title-按钮方案,actionURL-点击按钮触发的URL
  @btn_orientation = btn_orientation # 0-按钮竖直排列,1-按钮横向排列
  @hide_avatar = hide_avatar # 0-正常发消息者头像,1-隐藏发消息者头像
end

Public Instance Methods

build_message() click to toggle source
Calls superclass method
# File lib/DingTalk/core/action_card.rb, line 56
def build_message
  if @buttons.size == 1 then
    single_title = @buttons[0].title
    single_url = @buttons[0].action_url
    super.merge(
      {
        :actionCard => {
          :title => @title,
          :text => @text,
          :singleTitle => single_title,
          :singleURL => single_url,
          :btnOrientation => @btn_orientation,
          :hideAvatar => @hide_avatar
        }
      }
    )
  else
    super.merge(
      {
        :actionCard => {
          :title => @title,
          :text => @text,
          :btns => @buttons.map { | button | button.build_message },
          :btnOrientation => @btn_orientation,
          :hideAvatar => @hide_avatar
        }
      }
    )
  end
end
message_type() click to toggle source
# File lib/DingTalk/core/action_card.rb, line 52
def message_type
  TYPE::ACTION_CARD # 此消息类型为固定actionCard
end