Server : Apache System : Linux h2web276 4.9.0-0.bpo.12-amd64 #1 SMP Debian 4.9.210-1+deb9u1~deb8u1 (2020-06-09) x86_64 User : uid183121 ( 183121) PHP Version : 8.0.30 Disable Function : passthru,exec,system,popen,shell_exec,proc_open,pcntl_exec Directory : /home/clients/35966debc7d0d13be0a39d90b50635f3/sites/dd.noccanada.org/app/Models/ |
Upload File : |
<?php namespace App\Models; use Illuminate\Database\Eloquent\Model; use mysql_xdevapi\Exception; use Twilio; class Call extends Model { protected $table = 'calls'; protected $fillable = ['incidentID', 'personID', 'voiceID', 'status', 'response', 'sid']; public function makeCall() { // if(Call::where('status', 'in-progress')->count() > 0) return 'running'; // // $mySelf = $this; $this->update(['status' => 'in-progress']); $phone = false; if($this->person()->contactPhone == 1) $phone = $this->person()->phone_mobile1; else if($this->person()->contactPhone2 == 1) $phone = $this->person()->phone_mobile2; else if($this->person()->contactLand == 1) $phone = $this->person()->phone_land; if($phone) { try { $d = Twilio::call($phone, function (\Twilio\TwiML\VoiceResponse $message) { $message->say('Please standby for an announcment from network operations center canada'); $message->play(url("/api/get/{$this->voice()->path}"), [ 'loop' => 2, ]); // $gather = $message->gather(array('numDigits' => 1)); // $gather->say('Please press 1 if you intend on going'); $message->say('If you don\'t want to get future messages please send an email to remove@noccanada.org'); // $this->update(['response', $message]); },[ 'statusCallback' => url("/api/update/{$this->id}"), "statusCallbackMethod" => "POST", // 'contentType' => 'audio/webm' ]); $this->update(['sid' => $d->sid]); \File::append(public_path('log') .'/call-log.txt', [url("/api/get/{$this->voice()->path}"), print_r($d,1)]); }catch (Exception $e) { $this->update(['status' => 'error! '.$phone.' - '.$e['message']]); } }else{ $this->update(['status' => 'no call made']); } } public function person() { return Person::find($this->personID); } public function incident() { return Incident::find($this->incidentID); } public function voice() { return Voice::find($this->voiceID); } }