JavaScript
chatwork
axios

axiosでチャットワークに投稿

More than 1 year has passed since last update.

即席で欲しい時があるのでメモ

const axios = require('axios')
const createMessage = (token, room_id, body) => (
  axios({
    method: 'post',
    url: `https://api.chatwork.com/v2/rooms/${room_id}/messages`,
    headers: {'X-ChatWorkToken': token},
    data: `body=${body}`
  })
)

createMessage(token,room_id, body).catch(console.log)
const axios = require('axios')
const createClient = token => {
  const client = axios.create({
    baseURL: 'https://api.chatwork.com/v2/',
    headers:   {'X-ChatWorkToken': token},
  })
  return {
    createMessage(room_id, body) {
      return client.post(`rooms/${room_id}/messages`, `body=${body}`)
    }
  }
}

 createClient(token).createMessage(room_id, body).catch(console.log)

リンク