Herewith I need to send a message to particular WhatsApp number by clicking a button. Twilio API used to send messages and configured by https://www.twilio.com/console. And also I registered and get ID and Token from Twilio to my personnel WhatsApp number. Below is my code.
abc.blade.php
<div class="col-md-6" align="center" style="margin-top: 30px;">
<button class="btn btn-sm pmd-btn-fab pmd-btn-flat pmd-ripple-effect btn-primary" type="button" style="margin-left: 10px; margin-top: 40px; width:100px;" onclick="sendMsg(this);">Upload</button></div>
<script type="text/javascript">
function sendMsg()
{
$.ajax({
url: "",
type: "GET",
dataType:"json",
success: function (data)
{
alert("OK");
}
});
}
</script>
Utils/Twilio.php
<?php
namespace Utils;
class Twilio {
private $sid = "AC967540fbaf69f951a3b42e229a93c110"; // Your Account SID from www.twilio.com/console
private $token = "67bbbd8e95339a3db91b503a3f02fa34"; // Your Auth Token from www.twilio.com/console
private $client;
public function __construct() {
$this->client = new \Twilio\Rest\Client($this->sid, $this->token);
}
public function sendSMS($from, $body, $to) {
$message = $this->client->messages->create(
$to, // Text this number
array(
'from' => $from, // From a valid Twilio number
'body' => $body
)
);
return $message->sid;
}
}
Controller.php
<?php
namespace App\Http\Controllers;
use NotificationChannels\ChatAPI\ChatAPIChannel;
use NotificationChannels\ChatAPI\ChatAPIMessage;
use Illuminate\Notifications\Notification;
use Utils\Twilio;
class Controller extends Notification
{
public function via($notifiable)
{
return [ChatAPIChannel::class];
}
public function toChatAPI()
{
$result = ChatAPIMessage::create()
->to(947xxxxxxxx) // your user phone
->content('Hi bro....');
return $result;
}
}
On button click function nothing happen. Thanks in advance.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire