ComandoController.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. namespace app\commands;
  3. use app\components\Whatsapp;
  4. use yii\console\Controller;
  5. class ComandoController extends Controller {
  6. public function actionEnviarMensaje() {
  7. $params = \Yii::$app->params;
  8. $wab = null;
  9. if(isset($params["wab"])) {
  10. $wab = $params["wab"];
  11. }
  12. if($wab === null) {
  13. $this->stdout("No existe la configuración\n");
  14. }
  15. $msgTo = "526621115643";
  16. $template = "laud_resumen_eventos";
  17. $template = "informe_de_eventos";
  18. $eventos = "5/5 eventos";
  19. $mensaje = "gracias por tu ";
  20. try {
  21. $wa = (new Whatsapp())
  22. ->set_access_token($wab["access-token"])
  23. ->msg_from($wab["phone-id"])
  24. ->msg_to($msgTo)
  25. ->template($template)
  26. ->add_body_param($eventos)
  27. ->add_body_param($mensaje)
  28. ->send_template_message();
  29. if($wa === null) {
  30. $this->stdout("Ocurrió un error al enviar el mensaje\n");
  31. return;
  32. }
  33. $this->stdout("Proceso terminado\n");
  34. } catch (\Exception $e) {
  35. $this->stdout("Error al enviar el mensaje: {$e->getMessage()}\n");
  36. }
  37. }
  38. }