Rocket.Chat推送消息
Rocket.Chat
是一個開源實時通訊平台, 支持Windows
, Mac OS
, Linux
. 支持聊天, 文件上傳, 視頻通話, 語音通話功能.
向Rocket.Chat推送消息
以下示例可以轉為別的語言的版本, 本示例使用Linux
平台的curl
測試, curl
非常強大.
登陸
首先需要登陸Rocket.Chat
服務器:
curl http://localhost:3000/api/v1/login -d "username=YourUserName&password=YourPassWord"
# 會返回一個json數據, 包含了userId和Token
{
"status": "success",
"data": {
"userId": "YourUserID",
"authToken": "YourAuthToken"
}
}
發送信息
使用返回的userId
和authToken
, 構造新的請求:
curl -H "X-Auth-Token: YourAuthToken" \
-H "X-User-Id: YourUserID" \
-H "Content-type:application/json" \
http://localhost:3000/api/v1/chat.postMessage \
-d '{ "channel": "#測試", "text": "This is a test! @all" }'
# 返回, 會包含時間戳, 頻道, 信息的id, 發送的用戶, @的用戶等信息
{
"ts": 1531986688452,
"channel": "#測試",
"message": {
"alias": "",
"msg": "This is a test! @all",
"attachments": [],
"parseUrls": true,
"groupable": false,
"ts": "2018-07-19T07:51:28.447Z",
"rid": "xxxxx",
"u": {
"_id": "YourChatId",
"username": "YourChatName",
"name": "xxxx"
},
"unread": true,
"mentions": [{
"_id": "all",
"username": "all"
}],
"channels": [],
"_updatedAt": "2018-07-19T07:51:28.448Z",
"_id": "YourChatId"
},
"success": true
}