Library supports DSL to build and sends DingtalkBot messages, driven by Vert.x and kotlinx.serialization.
You need a web hook and an optional signature (in robot settings) to create a DingtalkBot
:
val bot = DingtalkBot(WEB_HOOK, SIGNATURE)
There are three ways to send messages:
- Async
- Blocking
- Suspend
Sending messages is implemented by kotlin coroutines.
There are six types of messages:
- Text Message
- Markdown Message
- Link Message
- ActionCard Message
- FeedCard Message
Each of them has different data parameters and patterns in serialization.
TextMessage
is the simplest type of messages, which only contains a part of plain text.
Here is the way to build a TextMessage
:
val at = at {
atMobiles = listOf("+86-13800138000","+86-12345678987")
atAll = true
}
val message = textMessage("Hello, world.", at)
At
is optional, and atMobiles
includes people to be at. However, if atAll
is true
, dingtalk will ignore atMobiles
.
Parameter | Optional | Default Value |
---|---|---|
text |
No | - |
at |
Yes | null |
MarkdownMessag
is a kind of advanced TextMessage
. It has extra parameter —— title
and its text
supports markdown syntax.
Here is the way to build a MarkdownMessage
:
val message = markdownMessage {
title = "Hello, world"
text = "# Hello, World"
at = at{
atMobiles = listOf("+86-13800138000","+86-12345678987")
atAll = true
}
}
Similarly,At
is optional.
Parameter | Optional | Default Value |
---|---|---|
title |
No | - |
text |
No | - |
at |
Yes | null |
LinkMessage
is a kind of advanced TextMessage
as well. It has title
, messageUrl
, pictureUrl
further. Notice that the type of text
is plain.
Here is the way to build a LinkMessage
:
val message = linkMessage {
title = "Welcome to MechDancer"
text = "MechDancer is a robot competition team."
pictureUrl = "https://github.com/MechDancer/mechdancer.github.io/blob/master/css/images/mechdancer2.png?raw=true"
messageUrl = "http://mechdancer.org"
}
LinkMessage
has a picture in its body, and it's optional.
Parameter | Optional | Default Value |
---|---|---|
title |
No | - |
text |
No | - |
messageUrl |
No | - |
pictureUrl |
Yes | "" |