Closed dcsan closed 5 years ago
hi! I created a small repo to act as a test. you can see the code to send a message here. however sending a message just times out.
can you confirm that function is working?
I can receive messages but not send them.
https://github.com/dcsan/ackbot/blob/master/server/routes/bot/out.js#L27
router.get('/bot/out', function(req, res, next) {
let sendUrl = config.sendUrl
let data = {
"chatId": config.testChatId,
"token": config.token,
"messageType": 0, // MessageType, check below
"payload": {
"text": "from code"
}
}
debug.log('send uri:', sendUrl)
debug.log('send data:', data)
axios({
method: 'post',
url: sendUrl,
timeout: 3000,
data: data
})
.then( function(response) {
debug.log('send response', response)
res.json(data)
})
.catch(function (err) {
debug.error('failed to send')
// TODO - check what type of error
res.status(500).json({
status: 500,
msg: 'failed to send / timeout'
})
})
docs
请求数据为json格式,如下
{
"chatId": "bcdw2j234ko1",
"token": "abcd",
"messageType": 1, // MessageType, check below
"payload": {
"text": "Hello World"
}
}
返回格式如下
{
"code": 0,
"message": ""
}
chatId
为系统中生成的id,需提前获取或一直保存
请求中的messageType
和payload
遵循如下格式,messageType
需要和payload
格式对应,否则会报错
enum MessageType {
TEXT = 0,
IMAGE = 1,
URL_LINK = 2,
FILE = 3,
}
TextPayload {
text: string,
mention?: string[],
}
ImagePayload {
url: string,
}
UrlPayload {
sourceUrl: string,
title: string,
summary: string,
imageUrl: string,
}
FilePayload {
url: string,
name: string,
}
The doc was wrong, I updated the doc and related server config, now it should be working. Please refer to the doc for the latest endpoint of sending messages.
It is ex-api.botorange.com/message/send
now.
works! docs: https://github.com/botorange/xiaoju/wiki/API-Doc
I want to test sending a simple message. first, I can't see anywhere in the main dashboard to get
chatId
from the chats. but I assume I can use one from an incoming message?so I use that chatId to try and send a message, with the token (actually same token in dashboard is in the incoming message... maybe a security risk?)
But I just get a timeout...