All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.hn.robot.dingtalk.domain.TextMsg Maven / Gradle / Ivy

There is a newer version: 1.0.18
Show newest version
package com.hn.robot.dingtalk.domain;

import cn.hutool.json.JSONUtil;

/**
 * 描述: 钉钉消息
 *
 * @author shilvfei
 */
public class TextMsg {
    /**
     * 消息类型
     */
    private String msgtype;
    /**
     * 只有text类型 这个字段才生效
     */
    private At at;
    /**
     * 消息对象
     * 最后转成json的时候,需要将[msgContent]替换成[msgtype的值]
     */
    private Object msgContent;

    public At getAt() {
        return at;
    }

    public TextMsg setAt(At at) {
        this.at = at;
        return this;
    }

    public String getMsgtype() {
        return msgtype;
    }

    public Object getMsgContent() {
        return msgContent;
    }

    public Text text(){
        msgtype="text";
        Text text = new Text();
        msgContent = text;
        return text;
    }

    /**
     * link类型
     * @return Link
     */
    public Link link(){
        msgtype="link";
        Link link = new Link();
        msgContent = link;
        return link;
    }

    /**
     * markdown格式的消息
     * @param title 首屏会话透出的展示内容
     * @return Markdown
     */
    public Markdown markdown(String title){
        msgtype="markdown";
        Markdown markdown = new Markdown(title);
        msgContent = markdown;
        return markdown;
    }

    public FeedCard feedCard(){
        msgtype="feedCard";
        FeedCard feedCard = new FeedCard();
        msgContent = feedCard;
        return feedCard;
    }

    /**
     * 整体跳转ActionCard类型
     * @param title 首屏会话透出的展示内容
     * @return ActionCard
     */
    public ActionCard actionCard(String title){
        msgtype="actionCard";
        ActionCard actionCard = new ActionCard(title);
        msgContent = actionCard;
        return actionCard;
    }

    public String toJsonStr(){
        String jsonStr = JSONUtil.toJsonStr(this);
        jsonStr = jsonStr.replace("msgContent", msgtype);
        // JSONObject jsonObject = JSONObject.parseObject(jsonStr);
        // jonObject.put(msgtype,content);
        return jsonStr;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy