def test_send_actioncard(self): """测试发送整体跳转ActionCard消息功能""" btns1 = [{"title": "查看详情", "actionURL": "https://www.dingtalk.com/"}] actioncard1 = ActionCard( title='万万没想到,竟然...', text= '![选择](http://www.songshan.es/wp-content/uploads/2016/01/Yin-Yang.png) \n### 故事是这样子的...', btns=btns1, btn_orientation=1, hide_avatar=1) result = self.xiaoding.send_action_card(actioncard1) self.assertEqual(result['errcode'], 0) """测试发送单独跳转ActionCard消息功能""" btns2 = [{ "title": "支持", "actionURL": "https://www.dingtalk.com/" }, { "title": "反对", "actionURL": "http://www.back china.com/news/2018/01/11/537468.html" }] actioncard2 = ActionCard( title='万万没想到,竟然...', text= '![选择](http://www.songshan.es/wp-content/uploads/2016/01/Yin-Yang.png) \n### 故事是这样子的...', btns=btns2, btn_orientation=1, hide_avatar=1) result = self.xiaoding.send_action_card(actioncard2) self.assertEqual(result['errcode'], 0)
def send_msg(webhook, secret, msg): """ :param webhook: 钉钉机器人webhook :param secret: 钉钉机器人secret :msg 消息对象 """ # 初始化机器人小丁 xiaoding = DingtalkChatbot(webhook, secret=secret) # 构建消息体 btns = [ CardItem( title=msg["btn_label"][0]['title'], url=msg["btn_label"][0]['url'], ), CardItem( title=msg["btn_label"][1]['title'], url=msg["btn_label"][1]['url'], ) ] actioncard = ActionCard( title=msg["title"], text=msg["content"], btns=btns, btn_orientation=1, hide_avatar=0, ) # 发送卡片消息 xiaoding.send_action_card(actioncard)
is_at_all=True) # 2、提醒指定手机用户,需要在text参数中@用户 xiaoding.send_markdown( title='氧气文字', text='#### 广州天气\n' '> 9度,西北风1级,空气良89,相对温度73%\n\n' '> ![美景](http://www.sinaimg.cn/dy/slidenews/5_img/2013_28/453_28488_469248.jpg)\n' '> ###### 10点20分发布 [天气](http://www.thinkpage.cn/) \n', at_mobiles=at_mobiles) # 整体跳转ActionCard btns1 = [{"title": "查看详情", "actionURL": "https://www.dingtalk.com/"}] actioncard1 = ActionCard( title='万万没想到,竟然...', text= '![选择](http://www.songshan.es/wp-content/uploads/2016/01/Yin-Yang.png) \n### 故事是这样子的...', btns=btns1, btn_orientation=1, hide_avatar=1) xiaoding.send_action_card(actioncard1) # 单独跳转ActionCard # 1、两个按钮选择 btns2 = [{ "title": "支持", "actionURL": "https://www.dingtalk.com/" }, { "title": "反对", "actionURL": "http://www.back china.com/news/2018/01/11/537468.html"
def notification(model): link = "http://www.qihuofy.com/article?id=%s" % model.article_id button = [CardItem(title=model.submit_date, url=link)] content = noti_content(model) action = ActionCard(title='您有新的文章评论', text= content, btns=button, btn_orientation=1, hide_avatar=1) dt_bot.send_action_card(action)