wa_strapi
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

51 lignes
1.4 KiB

  1. "use strict";
  2. const messageModel = require("../../model/messageModel");
  3. const { parseMultipartData, sanitizeEntity } = require("strapi-utils");
  4. /**
  5. * Cron config that gives you an opportunity
  6. * to run scheduled jobs.
  7. *
  8. * The cron format consists of:
  9. * [SECOND (optional)] [MINUTE] [HOUR] [DAY OF MONTH] [MONTH OF YEAR] [DAY OF WEEK]
  10. *
  11. * See more details here: https://strapi.io/documentation/developer-docs/latest/concepts/configurations.html#cron-tasks
  12. */
  13. let clients = {};
  14. module.exports = {
  15. "*/10 * * * * *": async () => {
  16. const session_key = await strapi.api.message.services.message.distinctbyKey(
  17. {
  18. _sort: "session_datum_key:desc",
  19. state: "QUEUE",
  20. }
  21. );
  22. session_key.forEach(async (i)=>{
  23. if(!Object.keys(clients).includes(`${i["id"]}`)){
  24. clients[i["id"]] = null;
  25. messageModel.loadClient(i["session_data"],async (data)=>{
  26. var json = JSON.parse(data);
  27. if (json["STATUS"] == 1 && json["TYPE"] == "READY") {
  28. return clients[i["id"]] = json["DATA"];
  29. }
  30. else if(json["STATUS"] ==0){
  31. return;
  32. }
  33. });
  34. }
  35. })
  36. console.log(clients);
  37. // const messages = await strapi.api.message.services.message.find(
  38. // {
  39. // _sort: "session_datum_key:desc",
  40. // state: "QUEUE",
  41. // }
  42. // );
  43. // messages.forEach(async (message) => {
  44. // await strapi.api.message.services.message.update(
  45. // { id: message.id },
  46. // { state: "SENT" }
  47. // );
  48. // });
  49. },
  50. };