Commit 0e5e2336 authored by ryoii's avatar ryoii

Http api return messageId after send a message

parent 94d859a4
...@@ -175,12 +175,13 @@ fun main() { ...@@ -175,12 +175,13 @@ fun main() {
| target | Long | false | 987654321 | 发送消息目标好友的QQ号 | | target | Long | false | 987654321 | 发送消息目标好友的QQ号 |
| messageChain | Array | false | [] | 消息链,是一个消息对象构成的数组 | | messageChain | Array | false | [] | 消息链,是一个消息对象构成的数组 |
#### 响应: 返回统一状态码 #### 响应: 返回统一状态码(并携带messageId)
```json5 ```json5
{ {
"code": 0, "code": 0,
"msg": "success" "msg": "success",
"messageId": 1234567890 // 一个Long类型属性,标识本条消息,用于撤回和引用回复
} }
``` ```
...@@ -213,12 +214,13 @@ fun main() { ...@@ -213,12 +214,13 @@ fun main() {
| target | Long | false | 987654321 | 发送消息目标群的群号 | | target | Long | false | 987654321 | 发送消息目标群的群号 |
| messageChain | Array | false | [] | 消息链,是一个消息对象构成的数组 | | messageChain | Array | false | [] | 消息链,是一个消息对象构成的数组 |
#### 响应: 返回统一状态码 #### 响应: 返回统一状态码(并携带messageId)
```json5 ```json5
{ {
"code": 0, "code": 0,
"msg": "success" "msg": "success",
"messageId": 1234567890 // 一个Long类型属性,标识本条消息,用于撤回和引用回复
} }
``` ```
...@@ -251,12 +253,13 @@ fun main() { ...@@ -251,12 +253,13 @@ fun main() {
| target | Long | false | 987654321 | 引用消息的Message Source的Uid | | target | Long | false | 987654321 | 引用消息的Message Source的Uid |
| messageChain | Array | false | [] | 消息链,是一个消息对象构成的数组 | | messageChain | Array | false | [] | 消息链,是一个消息对象构成的数组 |
#### 响应: 返回统一状态码 #### 响应: 返回统一状态码(并携带messageId)
```json5 ```json5
{ {
"code": 0, "code": 0,
"msg": "success" "msg": "success",
"messageId": 1234567890 // 一个Long类型属性,标识本条消息,用于撤回和引用回复
} }
``` ```
...@@ -371,6 +374,9 @@ Content-Type:multipart/form-data ...@@ -371,6 +374,9 @@ Content-Type:multipart/form-data
},{ },{
"type": "FriendMessage", // 消息类型:GroupMessage或FriendMessage或各类Event "type": "FriendMessage", // 消息类型:GroupMessage或FriendMessage或各类Event
"messageChain": [{ // 消息链,是一个消息对象构成的数组 "messageChain": [{ // 消息链,是一个消息对象构成的数组
"type": "Source",
"uid": 123456
},{
"type": "Plain", "type": "Plain",
"text": "Miral牛逼" "text": "Miral牛逼"
}], }],
......
...@@ -20,10 +20,10 @@ import io.ktor.response.respondText ...@@ -20,10 +20,10 @@ import io.ktor.response.respondText
import io.ktor.routing.post import io.ktor.routing.post
import io.ktor.routing.routing import io.ktor.routing.routing
import kotlinx.serialization.Serializable import kotlinx.serialization.Serializable
import kotlinx.serialization.Transient
import net.mamoe.mirai.api.http.AuthedSession import net.mamoe.mirai.api.http.AuthedSession
import net.mamoe.mirai.api.http.SessionManager import net.mamoe.mirai.api.http.SessionManager
import net.mamoe.mirai.api.http.data.* 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.MessageChainDTO
import net.mamoe.mirai.api.http.data.common.VerifyDTO import net.mamoe.mirai.api.http.data.common.VerifyDTO
import net.mamoe.mirai.api.http.data.common.toMessageChain import net.mamoe.mirai.api.http.data.common.toMessageChain
...@@ -44,23 +44,26 @@ fun Application.messageModule() { ...@@ -44,23 +44,26 @@ fun Application.messageModule() {
miraiVerify<SendDTO>("/sendFriendMessage") { miraiVerify<SendDTO>("/sendFriendMessage") {
it.session.bot.getFriend(it.target).apply { 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") { miraiVerify<SendDTO>("/sendGroupMessage") {
it.session.bot.getGroup(it.target).apply { 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") { miraiVerify<SendDTO>("/sendQuoteMessage") {
it.session.messageQueue.quoteCache[it.target]?.apply { 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() } ?: throw NoSuchElementException()
call.respondStateCode(StateCode.Success)
} }
miraiVerify<SendImageDTO>("sendImageMessage") { miraiVerify<SendImageDTO>("sendImageMessage") {
...@@ -127,9 +130,10 @@ private data class SendImageDTO( ...@@ -127,9 +130,10 @@ private data class SendImageDTO(
@Serializable @Serializable
private class SendRetDTO( private class SendRetDTO(
val messageId: Long, val code: Int = 0,
@Transient val stateCode: StateCode = Success val msg: String = "success",
) : StateCode(stateCode.code, stateCode.msg) val messageId: Long
) : DTO
@Serializable @Serializable
private data class RecallDTO( private data class RecallDTO(
......
...@@ -31,7 +31,7 @@ import net.mamoe.mirai.utils.unsafeWeakRef ...@@ -31,7 +31,7 @@ import net.mamoe.mirai.utils.unsafeWeakRef
* @see QQ.sendMessage 发送群消息, 返回回执(此对象) * @see QQ.sendMessage 发送群消息, 返回回执(此对象)
*/ */
open class MessageReceipt<C : Contact>( open class MessageReceipt<C : Contact>(
private val source: MessageSource, val source: MessageSource,
target: C target: C
) { ) {
init { init {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment