resume.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import { io } from "socket.io-client"
  2. import axios from "axios"
  3. import { setTimeout } from "timers/promises"
  4. import chalk from "chalk"
  5. const axiosInstance = axios.create({
  6. baseURL: "http://47.98.225.28/api",
  7. headers: {
  8. Authorization:
  9. "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6InpvdW1hQWRtaW4iLCJzdWIiOjEsInJvbGVzIjpbImFkbWluIl0sImlhdCI6MTcyNjU4MTk1OH0.dQiHFYaDDa1qp4OpEHaH5SCZ9dafJ8uO9fAAc8HZgAo"
  10. }
  11. })
  12. const {
  13. data: { items: devices }
  14. } = await axiosInstance.post("/device", {
  15. page: { page: 1, limit: 1000 },
  16. search: {
  17. where: { online: true, busy: false, canSend: false },
  18. order: { name: "ASC" }
  19. }
  20. })
  21. for (let device of devices) {
  22. console.log(chalk.green(`${device.name} resume`))
  23. axiosInstance
  24. .post(
  25. `/device/${device.id}/sendMessage`,
  26. {
  27. action: "resume",
  28. data: { request: true, reset: true }
  29. },
  30. {
  31. timeout: 60000
  32. }
  33. )
  34. .catch(e => {
  35. console.log(chalk.red(e.message))
  36. })
  37. await setTimeout(500)
  38. }