LoginSignup
4
5

More than 5 years have passed since last update.

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

Last updated at Posted at 2017-11-06

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

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)

リンク

4
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
5