Skip to content

Dinger 2.5 支持的消息类型

Jaemon edited this page May 29, 2022 · 3 revisions

支持的消息类型

Dinger支持的消息类型

消息类型/Dinger类型 DingTalk(钉钉) WeTalk(企业微信) ByteTalk(飞书)
TEXT
MARKDOWN ×
IMAGETEXT ×
LINK × ×

 

图文、Link类型入门

dinger version

一、配置文件配置

spring:
  dinger:
    project-id: ${spring.application.name}
    default-dinger: dingtalk
    dinger-locations: classpath*:dinger/*.xml
    dingers:
      dingtalk:
        tokenId: 87dbeb7bc28894c3ycyl3d12457228ad309966275b5f427cd85f9025ebb520cf
        secret: AEQ74a9039ai01f2ljm017b90ycye9asg6335f97c658ff37ff371ec8120581c7f09
      wetalk:
        tokenId: 32865206-7082-46l5-8j39-2m7ycy6d868

 

二、启动类引入DingerScan注解

@SpringBootApplication
@DingerScan(basePackages = "com.jaemon.demo.dinger")
public class DemoApplication {
    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }
}

 

三、定义Dinger

方式1-注解方式

public interface UserDinger {
    // 图文类型
    @DingerImageText
    DingerResponse imageText(List<ImageTextDeo> images);

    // link类型, 只支持Dingtalk
    @DingerLink
    DingerResponse link(LinkDeo link);

}

 

方式2-Xml方式

xml方式需要新增dinger-locations配置项

spring:
  dinger:
    dinger-locations: classpath*:dinger/*.xml

UserDinger.java

public interface UserDinger {
    DingerResponse imageText(List<ImageTextDeo> images);

    DingerResponse link(LinkDeo link);
}

userDinger.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE dinger SYSTEM "dinger.dtd">
<!DOCTYPE dinger PUBLIC "-//AnswerAIL//DTD Dinger 2.0//EN" "dinger.dtd">

<dinger namespace="com.jaemon.demo.dinger.UserDinger">
    <message id="imageText" type="IMAGETEXT" />

    <message id="link" type="LINK" />
</dinger>

 

四、使用Dinger

@Component
public class AppInit implements InitializingBean {
    @Autowired
    private UserDinger userDinger;
    @Override
    public void afterPropertiesSet() throws Exception {
        String picUrl = "http://res.mail.qq.com/node/ww/wwopenmng/images/independent/doc/test_pic_msg1.png";
        List<ImageTextDeo> images = new ArrayList<>();
        images.add(
                ImageTextDeo.instance(
                        "Dinger Github", "https://github.com/AnswerAIL/dingtalk-spring-boot-starter/", picUrl
                )
        );
        images.add(
                ImageTextDeo.instance(
                        "Dinger Gitee", "https://gitee.com/jaemon/dingtalk-spring-boot-starter", picUrl
                )
        );
        images.add(
                ImageTextDeo.instance(
                        "Dinger Wiki", "https://gitee.com/jaemon/dingtalk-spring-boot-starter/wikis", picUrl
                )
        );
        // 发送图文类型消息
        userDinger.imageText(images);


        // 发送link类型消息, 只支持钉钉
        userDinger.link(
                LinkDeo.instance(
                        "Dinger-叮鸽中间件",
                        "Dinger(叮鸽),SpringBoot集成钉钉/企业微信群机器人实现消息通知中间件。",
                        "https://gitee.com/jaemon/dingtalk-spring-boot-starter",
                        picUrl
                )
        );
    }
}
Clone this wiki locally