Last active
February 11, 2021 16:49
-
-
Save cvega93/22d8af6a675f488af68b6c0a18f3fc01 to your computer and use it in GitHub Desktop.
Revisions
-
cvega93 revised this gist
Feb 11, 2021 . 1 changed file with 5 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -16,7 +16,7 @@ public function __construct() } public function interviewResult($to, $name) // EJEMPLO DE COMO MANDAR EL MENSAJE { $params = array( 0 => ['default' => $name] @@ -30,8 +30,8 @@ public function sendMessage($to, $templateName, $lang, $params) // return 'holi'; $accessKey = "XXXX"; $channel_id = "XXXX"; $report_url = "XXXXXX"; // ACA RECIBES UN WEBHOOK CON EL STATUS DEL ENVÍO DEL MENSAJE $nameSpace = "XXXXXXX"; if (!config('services.messagebird.enabled')) { return 'ok'; } @@ -70,7 +70,7 @@ public function sendMessage($to, $templateName, $lang, $params) // LA VARIABLE 1 ES EL NOMBRE, MUY IMPORTANTE, LUEGO LOS OTRAS VARIABLES SON LAS POSUCIONES DEL ARRAY. public function sendTemplateMessagebird() { request()->merge(['password' => config('services.messagebird.local_key')]); // TRICK PARA VALIDAR UN TOKEN PARA MÁS SEGURIDAD JE request()->validate([ 'key' => 'required|same:password', 'contact.phone' => 'required|string|max:20', @@ -84,7 +84,7 @@ public function sendTemplateMessagebird() $params = request()->input('params'); $parsed_params = [ ['default' => request()->input('contact.first_name')] // LA POSICION 1 SIEMPRE ES EL NOMBRE CREAR LAS PLANTILLAS CONSIDERANDO ESTO ]; if ($params) { foreach($params as $param) { -
cvega93 revised this gist
Feb 11, 2021 . 1 changed file with 0 additions and 55 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -16,61 +16,6 @@ public function __construct() } public function interviewResult($to, $name) { $params = array( -
cvega93 revised this gist
Feb 11, 2021 . No changes.There are no files selected for viewing
-
cvega93 revised this gist
Feb 11, 2021 . 1 changed file with 33 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -119,3 +119,36 @@ public function sendMessage($to, $templateName, $lang, $params) return $res; } } // CON ESTO CREAS LA INTERFÁZ PARA INTEGRARLO A ACTIVE CAMPAIGN. // LA VARIABLE 1 ES EL NOMBRE, MUY IMPORTANTE, LUEGO LOS OTRAS VARIABLES SON LAS POSUCIONES DEL ARRAY. public function sendTemplateMessagebird() { request()->merge(['password' => config('services.messagebird.local_key')]); request()->validate([ 'key' => 'required|same:password', 'contact.phone' => 'required|string|max:20', 'template_name' => 'required|string|max:100', 'contact.first_name' => 'string|max:50', 'params' => 'array', ]); $to = str_replace(['+', ' '], '', request()->input('contact.phone')); $templateName = request()->input('template_name'); $params = request()->input('params'); $parsed_params = [ ['default' => request()->input('contact.first_name')] ]; if ($params) { foreach($params as $param) { $parsed_params[] = ['default' => $param]; } } return $this->messageBirdService->sendMessage($to, $templateName, 'es', $parsed_params); } -
cvega93 created this gist
Feb 11, 2021 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,121 @@ <?php namespace App\Http\Services\User; //Service Base use App\Http\Services\ServiceBase; use Illuminate\Support\Facades\Log; /** * Handles complex login and uses the model repo to connect to the db */ class MessageBirdService extends ServiceBase { public function __construct() { } public function welcomeMessage($to, $name) { $params = array( 0 => ['default' => $name] ); $fixed_number = str_replace(' ', '', $to); Log::info($fixed_number); return $this->sendMessage($fixed_number, 'welcome', 'es_MX', $params); } public function confirmInterview($to, $name, $interview_date) { $params = array( 0 => ['default' => $name], 1 => ['default' => $interview_date], ); $fixed_number = str_replace(' ', '', $to); Log::info($fixed_number); return $this->sendMessage($fixed_number, 'confirm_interview_2', 'es', $params); } public function interviewReminder($to, $name) { $params = array( 0 => ['default' => $name] ); $fixed_number = str_replace(' ', '', $to); Log::info($fixed_number); return $this->sendMessage($fixed_number, 'interview_reminder_last_2', 'es', $params); } public function reminder_interview_morning($to, $name, $interview_date) { $params = array( 0 => ['default' => $name], 1 => ['default' => "Diana"], 2 => ['default' => $interview_date], ); $fixed_number = str_replace(' ', '', $to); Log::info($fixed_number); return $this->sendMessage($fixed_number, 'reminder_interview_morning_2', 'es', $params); } public function reminder_interview_30minutes($to, $name, $interviewer_name, $interview_link) { $params = array( 0 => ['default' => $name], 1 => ['default' => $interviewer_name], 2 => ['default' => $interview_link] ); $fixed_number = str_replace(' ', '', $to); Log::info($fixed_number); return $this->sendMessage($fixed_number, 'reminder_interview_30minutes_3', 'es', $params); } public function interviewResult($to, $name) { $params = array( 0 => ['default' => $name] ); $fixed_number = str_replace(' ', '', $to); return $this->sendMessage($fixed_number, 'user_admitted', 'es', $params); } public function sendMessage($to, $templateName, $lang, $params) { // return 'holi'; $accessKey = "XXXX"; $channel_id = "XXXX"; $report_url = "XXXXXX"; $nameSpace = "d39b8cd9_2244_4437_9203_1a607f87fb11"; if (!config('services.messagebird.enabled')) { return 'ok'; } $content_array = array( 'type' => 'hsm', 'to' => $to, 'channelId' => $channel_id, "reportUrl" => $report_url, 'content' => array( 'hsm' => array( 'namespace' => $nameSpace, 'templateName' => $templateName, 'language' => array( 'policy' => 'deterministic', 'code' => $lang, ), 'params' => $params ), ), ); $parsedContent = json_encode($content_array); $curl = "curl -X POST 'https://conversations.messagebird.com/v1/conversations/start' -H 'Authorization: AccessKey $accessKey' -H 'Content-Type: application/json' -d '$parsedContent'"; // Log::info($curl); $res = shell_exec($curl); \App\Entities\MessagebirdLog::create(['response' => $res]); return $res; } }