MOON
Server: Apache
System: Linux e2e-78-16.ssdcloudindia.net 3.10.0-1160.45.1.el7.x86_64 #1 SMP Wed Oct 13 17:20:51 UTC 2021 x86_64
User: imensosw (1005)
PHP: 8.0.30
Disabled: exec,passthru,shell_exec,system
Upload Files
File: /home/imensosw/liftcincy.imenso.co/app/Console/Commands/ReminderTextOfLiveEvent.php
<?php

/*
    Reminder Text (Live Events)
    TRIGGER AT 9AM THE DAY OF A LIVE EVENT
*/

namespace App\Console\Commands;

use Illuminate\Console\Command;
use App\LiveEvent;
use App\EventTicket;
use App\Partner;
use App\User;
use Notification;
use Mail;
use Twilio\Rest\Client;
use Illuminate\Support\Facades\Log;

use App\CountryCode;

class ReminderTextOfLiveEvent extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'command:remindertextofliveevent';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Trigger at 9AM the day of a live event';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {
        $start_date = date('Y-m-d');
        $start_time = date('H:i:s');
        $checkTime = "09:00:00";
        $events = EventTicket::join('live_events', 'event_tickets.event_id', '=', 'live_events.id')
                    ->join('users','event_tickets.volunteer_id', 'users.id')
                    ->whereDate('live_events.start_date', $start_date)
                    ->select('live_events.*', 'users.name', 'users.email', 'users.org_contact','users.first_name')
                    ->get();
        //$arr = (array) $events;
        //Log::info('TRIGGER AT 9AM:',$arr);
        // if(date('H:i:s') == $checkTime)
        // {
            if($events->count())
            {
                //Log::info('TRIGGER AT 9AM:IN');
                foreach ($events as $key => $event) 
                {
                    $start_time = date('h:i A', strtotime($event->start_time));
                    //Log::info('TRIGGER AT 9AM:foreach');
                    //$volunteer_contact = "+91".$event->org_contact;
                    $volunteer_name = $event->first_name;
                   // $message = "Hey {$volunteer_name}! Just a reminder that you have cashed in to see {$event->event_title} TONIGHT at {$event->address_location}! The show starts at {$start_time}. It would mean the world to us if you'd text photos of you and any friends at the show, or tag us on social media @concertedusa! This helps us get folks excited and motivated to serve the community. Thank you for showing up for your city through service. 💖"; 
                    $message = "Hey {$volunteer_name}! Just a reminder that you have cashed in to see {$event->event_title} TONIGHT at {$event->address_location}! The show starts at {$start_time}. It would mean the world to us if you'd text photos of you and any friends at the show, or tag us on social media @concertedusa! This helps us get folks excited and motivated to serve the community. Thank you for showing up for your city through service. πŸ’– ";
                    if($event->org_contact!="")
                    {
                    
                        try {
                            $this->send_text_message($message, $event);  
                            Log::info('Message (TRIGGER AT 9AM THE DAY OF A LIVE EVENT) send to - '.$volunteer_name.' at '.date('Y-m-d H:i:s'));
    
                        } catch (\Exception $e) {
                            Log::info('TRIGGER AT 9AM ERROR:',(array)$e);
    
                        //return $e->getMessage();
                        }      
                    }
                    
               }
            }
        // }

    }
    
    public function send_text_message($message,$volunteer)
    {
        //try {

            $account_sid = \Config::get("app.TWILIO_SID");
            $auth_token = \Config::get("app.TWILIO_AUTH_TOKEN");
            $twilio_number = \Config::get("app.TWILIO_NUMBER");
            $countryCode = \Config::get('app.COUNTRY_CODE');
            // $countryCode = $this->getCountryCode($volunteer->address_country);
            if($volunteer->org_contact!=null){
                $contact_volunteer = $countryCode."".$volunteer->org_contact;
                //$contact_volunteer = $volunteer->org_contact;
                $client = new Client($account_sid, $auth_token);
                $recipients = $contact_volunteer;
                $message = $message;
                $client->messages->create($recipients, ['from' => $twilio_number, 'body' => $message]);
            }
            
            return true;
        
        //} catch (\Exception $e) {
        
            //return false;
        //}
        
        return false;
    }
}