Http api return messageId after send a message

This commit is contained in:
ryoii 2020-02-23 20:33:03 +08:00
parent 94d859a4e6
commit 0e5e2336ff
3 changed files with 28 additions and 18 deletions

View File

@ -175,12 +175,13 @@ fun main() {
| target | Long | false | 987654321 | 发送消息目标好友的QQ号 |
| messageChain | Array | false | [] | 消息链,是一个消息对象构成的数组 |
#### 响应: 返回统一状态码
#### 响应: 返回统一状态码并携带messageId
```json5
{
"code": 0,
"msg": "success"
"msg": "success",
"messageId": 1234567890 // 一个Long类型属性标识本条消息用于撤回和引用回复
}
```
@ -213,12 +214,13 @@ fun main() {
| target | Long | false | 987654321 | 发送消息目标群的群号 |
| messageChain | Array | false | [] | 消息链,是一个消息对象构成的数组 |
#### 响应: 返回统一状态码
#### 响应: 返回统一状态码并携带messageId
```json5
{
"code": 0,
"msg": "success"
"msg": "success",
"messageId": 1234567890 // 一个Long类型属性标识本条消息用于撤回和引用回复
}
```
@ -251,12 +253,13 @@ fun main() {
| target | Long | false | 987654321 | 引用消息的Message Source的Uid |
| messageChain | Array | false | [] | 消息链,是一个消息对象构成的数组 |
#### 响应: 返回统一状态码
#### 响应: 返回统一状态码并携带messageId
```json5
{
"code": 0,
"msg": "success"
"msg": "success",
"messageId": 1234567890 // 一个Long类型属性标识本条消息用于撤回和引用回复
}
```
@ -370,7 +373,10 @@ Content-Typemultipart/form-data
}
},{
"type": "FriendMessage", // 消息类型GroupMessage或FriendMessage或各类Event
"messageChain": [{ // 消息链,是一个消息对象构成的数组
"messageChain": [{ // 消息链,是一个消息对象构成的数组
"type": "Source",
"uid": 123456
},{
"type": "Plain",
"text": "Miral牛逼"
}],

View File

@ -20,10 +20,10 @@ import io.ktor.response.respondText
import io.ktor.routing.post
import io.ktor.routing.routing
import kotlinx.serialization.Serializable
import kotlinx.serialization.Transient
import net.mamoe.mirai.api.http.AuthedSession
import net.mamoe.mirai.api.http.SessionManager
import net.mamoe.mirai.api.http.data.*
import net.mamoe.mirai.api.http.data.common.DTO
import net.mamoe.mirai.api.http.data.common.MessageChainDTO
import net.mamoe.mirai.api.http.data.common.VerifyDTO
import net.mamoe.mirai.api.http.data.common.toMessageChain
@ -44,23 +44,26 @@ fun Application.messageModule() {
miraiVerify<SendDTO>("/sendFriendMessage") {
it.session.bot.getFriend(it.target).apply {
sendMessage(it.messageChain.toMessageChain(this)) // this aka QQ
val receipt = sendMessage(it.messageChain.toMessageChain(this)) // this aka QQ
receipt.source.ensureSequenceIdAvailable()
call.respondDTO(SendRetDTO(messageId = receipt.source.id))
}
call.respondStateCode(StateCode.Success)
}
miraiVerify<SendDTO>("/sendGroupMessage") {
it.session.bot.getGroup(it.target).apply {
sendMessage(it.messageChain.toMessageChain(this)) // this aka Group
val receipt = sendMessage(it.messageChain.toMessageChain(this)) // this aka Group
receipt.source.ensureSequenceIdAvailable()
call.respondDTO(SendRetDTO(messageId = receipt.source.id))
}
call.respondStateCode(StateCode.Success)
}
miraiVerify<SendDTO>("/sendQuoteMessage") {
it.session.messageQueue.quoteCache[it.target]?.apply {
quoteReply(it.messageChain.toMessageChain(group))
val receipt = quoteReply(it.messageChain.toMessageChain(group))
receipt.source.ensureSequenceIdAvailable()
call.respondDTO(SendRetDTO(messageId = receipt.source.id))
} ?: throw NoSuchElementException()
call.respondStateCode(StateCode.Success)
}
miraiVerify<SendImageDTO>("sendImageMessage") {
@ -127,9 +130,10 @@ private data class SendImageDTO(
@Serializable
private class SendRetDTO(
val messageId: Long,
@Transient val stateCode: StateCode = Success
) : StateCode(stateCode.code, stateCode.msg)
val code: Int = 0,
val msg: String = "success",
val messageId: Long
) : DTO
@Serializable
private data class RecallDTO(

View File

@ -31,7 +31,7 @@ import net.mamoe.mirai.utils.unsafeWeakRef
* @see QQ.sendMessage 发送群消息, 返回回执此对象
*/
open class MessageReceipt<C : Contact>(
private val source: MessageSource,
val source: MessageSource,
target: C
) {
init {