This is middleware for conncet. This post message to Chatwork according to a chatwork property of request.
npm Install conncet-post-chatwork-message
Set API Token. See docment of the Chatwork about detail of API Token.
postChatwork(YOUR_TOKEN)
req.chatwork = {
roomId: YOUR_ROOM_ID,
message: "test message"
}
import connect from 'connect'
import postChatwork from 'conncet-post-chatwork-message'
let app = connect()
.use((req, res, next) => {
req.chatwork = {
roomId: process.env.CHATWORK_ROOM_ID,
message: "test message"
}
next()
})
.use(postChatwork(process.env.CHATWORK_TOKEN))
.use((req, res) => res.end('OK'))
.use((err, req, res, next) => {
console.error(err.stack)
res.statusCode = 500
res.end('Something broke!')
})
.listen(process.env.PORT || 3000);
Start a server.
cd expample
npm install
env CHATWORK_TOKEN=YOUR_TOKEN CHATWORK_ROOM_ID=YOUR_ROOM_ID npm start
Send a request
curl -X GET http://localhost:3000
env CHATWORK_TOKEN=YOUR_TOKEN CHATWORK_ROOM_ID=YOUR_ROOM_ID npm test