This commit is contained in:
@@ -11,6 +11,7 @@ use App\Services\CustomerService;
|
||||
use Illuminate\Support\Facades\Session;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Twilio\Rest\Client;
|
||||
|
||||
use Carbon\Carbon;
|
||||
|
||||
@@ -234,9 +235,10 @@ class CustomersController extends Controller
|
||||
$expired = Carbon::now();
|
||||
$expired = new Carbon();
|
||||
$expired = $expired->addHours(24);
|
||||
|
||||
$nokp = $request->noic;
|
||||
|
||||
|
||||
$nokp = $request->noic_otp;
|
||||
$customer = Http::get(config('api.url'). '/api/customers/'.$nokp)->json();
|
||||
$recipient = '+6'.$customer[0]['telefon'];
|
||||
//pembinaan token
|
||||
function token($length) {
|
||||
$characters = array(
|
||||
@@ -268,7 +270,8 @@ class CustomersController extends Controller
|
||||
'expired' => $expired,
|
||||
'kodcaw' => $auth_user['cawangan']
|
||||
]);
|
||||
|
||||
$message = "Your TAC code is " . $random;
|
||||
$this->sendWhatsAppMessage($message, $recipient);
|
||||
return response()->json(['otp'=>$random]);
|
||||
}
|
||||
}else{
|
||||
@@ -279,7 +282,8 @@ class CustomersController extends Controller
|
||||
'expired' => $expired,
|
||||
'kodcaw' => $auth_user['cawangan']
|
||||
]);
|
||||
|
||||
$message = "Your TAC code is " . $random;
|
||||
$this->sendWhatsAppMessage($message, $recipient);
|
||||
return response()->json(['otp'=>$random]);
|
||||
}
|
||||
}
|
||||
@@ -295,7 +299,8 @@ class CustomersController extends Controller
|
||||
'expired' => $expired,
|
||||
'kodcaw' => $auth_user['cawangan']
|
||||
]);
|
||||
|
||||
$message = "Your TAC code is " . $random;
|
||||
$this->sendWhatsAppMessage($message, $recipient);
|
||||
return response()->json(['otp'=>$random]);
|
||||
}
|
||||
}else{
|
||||
@@ -306,10 +311,34 @@ class CustomersController extends Controller
|
||||
'expired' => $expired,
|
||||
'kodcaw' => $auth_user['cawangan']
|
||||
]);
|
||||
|
||||
$message = "Your TAC code is " . $random;
|
||||
$this->sendWhatsAppMessage($message, $recipient);
|
||||
return response()->json(['otp'=>$random]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function listenToReplies(Request $request)
|
||||
{
|
||||
$from = $request->input('From');
|
||||
|
||||
$message = "Someone send you a message on whatsapp";
|
||||
|
||||
$this->sendWhatsAppMessage($message, $from);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
public function sendWhatsAppMessage(string $message, string $recipient)
|
||||
{
|
||||
$twilio_whatsapp_number = getenv('TWILIO_WHATSAPP_NUMBER');
|
||||
$account_sid = getenv("TWILIO_SID");
|
||||
$auth_token = getenv("TWILIO_AUTH_TOKEN");
|
||||
$from = "whatsapp:".$twilio_whatsapp_number;
|
||||
$to = "whatsapp:".$recipient;
|
||||
|
||||
$client = new Client($account_sid, $auth_token);
|
||||
return $client->messages->create($to, array('from' => $from, 'body' => $message));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user