forked from mHealthKenya/ushauri_dashboard
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8f16062
commit cb7bee4
Showing
4 changed files
with
117 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use Illuminate\Http\Request; | ||
|
||
use\App\Models\UshauriInbox; | ||
use\App\Models\UshauriOutbox; | ||
use Log; | ||
|
||
|
||
class ReceiverController extends Controller | ||
{ | ||
public function index(Request $request) | ||
{ | ||
if ($request->to == '40149') { | ||
|
||
// dd($request->all()); | ||
|
||
$inbox = new UshauriInbox; | ||
|
||
$inbox->destination = $request->to; | ||
$inbox->source = $request->from; | ||
$inbox->msg = $request->text; | ||
$inbox->receivedtime = $request->date; | ||
$inbox->reference = $request->id; | ||
$inbox->LinkId = $request->linkId; | ||
|
||
$inbox->save(); | ||
|
||
$lastID1 = $inbox->id; | ||
$task = 1; | ||
$this->task($task, $lastID1); | ||
} | ||
} | ||
|
||
function task($task, $LastInsertId) | ||
{ | ||
Log::info("ID: " . $LastInsertId . ", TASK: " . $task); | ||
switch ($task) { | ||
case 1: | ||
|
||
$ch = curl_init(); | ||
|
||
curl_setopt($ch, CURLOPT_URL, "http://ushaurinode.localhost/receiver/$LastInsertId"); | ||
curl_setopt($ch, CURLOPT_HEADER, 0); | ||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); | ||
curl_exec($ch); | ||
|
||
curl_close($ch); | ||
echo 'Done task 1'; | ||
break; | ||
default: | ||
break; | ||
} | ||
} | ||
|
||
public function ushauri_callback(Request $request) | ||
{ | ||
|
||
//check incoming id and update single sms with telco status | ||
|
||
$updateDetails = [ | ||
'callback_status' => $request->get('status'), | ||
'failure_reason' => $request->get('failureReason') | ||
]; | ||
|
||
// return $request; | ||
|
||
$sms = UshauriOutbox::where('message_id', $request->id)->first(); | ||
if ($sms) { | ||
$sms = UshauriOutbox::where('message_id', $request->id) | ||
->update($updateDetails); | ||
} | ||
} | ||
} |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
namespace App\Models; | ||
|
||
use Illuminate\Database\Eloquent\Factories\HasFactory; | ||
use Illuminate\Database\Eloquent\Model; | ||
|
||
class UshauriInbox extends Model | ||
{ | ||
use HasFactory; | ||
// protected $connection = 'ushauri'; | ||
public $table = 'tbl_incoming'; | ||
public $timestamps = false; | ||
|
||
protected $fillable = [ | ||
'destination', 'source', 'msg', 'receivedtime', 'reference', 'LinkId' | ||
]; | ||
} |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
namespace App\Models; | ||
|
||
use Illuminate\Database\Eloquent\Factories\HasFactory; | ||
use Illuminate\Database\Eloquent\Model; | ||
|
||
class UshauriOutbox extends Model | ||
{ | ||
use HasFactory; | ||
|
||
public $table = 'tbl_clnt_outgoing'; | ||
public $timestamps = false; | ||
|
||
protected $fillable = [ | ||
'destination', 'source', 'msg', 'updated_at', 'deleted_at', 'created_at', 'status', 'responded', 'message_type_id', 'content_id', 'recepient_type', 'created_by', 'updated_by', 'is_deleted', 'clnt_usr_id', 'ushauri_id', 'db_source', 'message_id', 'cost', 'callback_status', 'failure_reason' | ||
]; | ||
} |
This file contains 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 characters