Skip to content

Commit

Permalink
sms receiver merged
Browse files Browse the repository at this point in the history
  • Loading branch information
Ronald-pro committed Nov 22, 2023
1 parent 8f16062 commit cb7bee4
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 1 deletion.
76 changes: 76 additions & 0 deletions app/Http/Controllers/ReceiverController.php
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);
}
}
}
18 changes: 18 additions & 0 deletions app/Models/UshauriInbox.php
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'
];
}
18 changes: 18 additions & 0 deletions app/Models/UshauriOutbox.php
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'
];
}
6 changes: 5 additions & 1 deletion routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,9 @@


Route::middleware('auth:api')->get('/user', function (Request $request) {
return $request->user();
return $request->user();
});


Route::post('/sms/receiver', 'App\Http\Controllers\ReceiverController@index');
Route::post('/sms/callback/ushauri', 'App\Http\Controllers\ReceiverController@ushauri_callback');

0 comments on commit cb7bee4

Please sign in to comment.