Whatsapp API - send a notification message to another phone number - php

I was looking for a way to send notifications directly to the customer phone number using the Whatsapp API
I found an article on a site that explains in detail how to activate and use the Whatsapp API.
Add the phone number +34 644 76 66 43 into your Phone Contacts. (Name it it as you wish)
Send this message "I allow callmebot to send me messages" to the new Contact created (using WhatsApp of course)
Wait until you receive the message "API Activated for your phone number. Your APIKEY is 123123" from the bot.
Note: If you don't receive the ApiKey in 2 minutes, please try again after 24hs.
The WhatsApp message from the bot will contain the apikey needed to send messages using the API.
You can send text messages using the API after receiving the confirmation.
Perfect receipt apikey
How to send WhatsApp Messages from PHP using CURL Library
It is very simple to send WhatsApp messages from PHP using the cURL Library. I would recommend to create a function and then call to the function every time that you want to send a message.
First, create the function "send_whatsapp" in your php code as follow:
function send_whatsapp($message="Test"){
$phone="NUMBER"; // Enter your phone number here
$apikey="YOUR_API_KEY"; // Enter your personal apikey received in step 3 above
$url='https://api.callmebot.com/whatsapp.php?source=php&phone='.$phone.'&text='.urlencode($message).'&apikey='.$apikey;
if($ch = curl_init($url))
{
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);
$html = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
// echo "Output:".$html; // you can print the output for troubleshooting
curl_close($ch);
return (int) $status;
}
else
{
return false;
}
}
Just update the $phone and $apikey variable with the ones that you obtained during the step 3 above.
And then call to the function from any place in your code.
send_whatsapp("this is a test from PHP"); //Text message that your would like to send
You can call to the send_whatsapp function from different places in your code.
QUESTION
Perfect this will send me a message every time to the number I specified to activate the notification system.
But what if I want to send it not to my number but to the customer number?

I believe you're missing two concepts here. If you want to send messages from your personal phone number, you need to host & run your own solution (I don't think you'd like to allow anybody else out there to get all your stuff).
If you are asking for a service provider to set up a number for you and offer you a gateway service for that purpose, there are several alternatives out there. Google them. You'll find two options; Facebook/Whatsapp API connected providers and 'free riders' that will set that up for you at a cost.
The solution you mention is called call me bot and it is just to send self notifications and not for sending out messages to third parties. I am hosting a similar solution (https://github.com/inUtil-info/whin-use-cases) but is the same situation. To prevent span, you are not allowed to send messages to anyone but you.

Related

Invitee is in inviter tenant: Azure AD Invitations Endpoint Error

I want to call the Invitations API to invite users to sign in via Microsoft Graph API.
My code works for most of the emails that I call the API on, however for some emails, I get this error:
{
"error": {
"code": "BadRequest",
"message": "Invitee is in inviter tenant",
"innerError": {
"request-id": <request id>,
"date": 2019-06-03T05:51:21
}
}
}
Any idea why this issue occurs?
To be clear, when I first called the API on this email, the invitation email was sent successfully. However, after a few times of testing, I get this error.
I initially suspected that clicking on the 'Get Started' button in the email caused on this error and tested this hypothesis on an Outlook email. However, after clicking on the 'Get Started' button for the test email and calling the API again, the invitation email is still sent as per normal.
My code snippet is as follows:
$curlStat = curl_init();
$feedURL = 'https://graph.microsoft.com/v1.0/invitations';
$data_body = Array(
'invitedUserEmailAddress' => <test-email>,
'inviteRedirectUrl' => <my-redirect-url>,
'sendInvitationMessage' => true
);
$headers = array(
"Authorization: Bearer " . <my-access-token>,
"Content-Type: application/json"
);
$data_body = json_encode($data_body);
curl_setopt($curlStat, CURLOPT_URL, $feedURL);
curl_setopt($curlStat, CURLOPT_POST, true);
curl_setopt($curlStat, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curlStat, CURLOPT_POSTFIELDS, $data_body);
curl_setopt($curlStat, CURLOPT_RETURNTRANSFER, true);
$emailOutput = curl_exec($curlStat);
curl_close($curlStat);
I'm aware of two conditions that cause this (or similar) errors to fire:
You're attempting to invite someone with an address from one of the verified domains. In other words, if your tenant lists company.onmicrosoft.com and company.com as verified domains, attempting to invite an address ending in #company.onmicrosoft.com or #company.com will fail.
The external email address you supplied already exists in the tenant (typically because they've already accepted a previous invitation).
Both of these boil down to the same root cause: you cannot send an invitation to an email address that has already been assigned to an existing user.
As for why you could send an invitation immediately after accepting a prior invitation, this is likely just a race condition. It takes a few moments for the invitation to get processed, the user record created, and the changes to propagate across your AAD tenant. Try waiting for 1 minute after accepting the invite and I suspect you'll consistently see this error.

Detect Disposable Email with Garbage Domain

I am developing website using php/codeigniter.
I have downloaded a list of temporary email domains from github (https://gist.github.com/adamloving/4401361)
I integrated this to my website to filter and validate email address.But I noticed that some domains are garbage and cannot detect by the list provided.
Please image below.
Currently Im using this code to filter/validate emails:
public function is_temp_mail($mail='')
{
$this->db->select('domain');
$this->db->from('table_disposal_email_domains');
$domains=$this->db->get()->result();
foreach($domains as $domain)
{
list(,$mail_domain) = explode('#',$mail);
if(strcasecmp($mail_domain, $domain->domain) == 0){
return true;
}
}
return false;
}
How to block garbage domains.Please help.
One of the issue with disposable emails is that new domains are added daily. So, maintaining your own list isn't gonna be enough after a few days.
You can use the validator.pizza API, which is free and updated frequently.
Disclaimer: I made this API 😊
I wrote a simple API for determining the domains of temporary mails, all you need to determine the temporary mail is to send a GET request:
https://api.testmail.top/domain/check/data=example#mail.com&ip=8.8.8.8
with authorization header:
Authorization: Bearer XXXXXXXXXX.XXXXXXXXXX.XXXXXXXXXX
and in response you will receive a message like this if the mail turns out to be temporary:
{
"error": 0,
"result": false,
"message": "This domain is in Blacklist"
}
you will receive such an answer if the mail turns out to be trusted (something like gmail.com or yahoo.com):
{
"error": 0,
"result": true,
"message": "This domain is in Whitelist"
}
I have described error codes and more detailed instructions on this page
It would be good if you use a third party package to help you on blocking temporary email domains. You can use MailboxValidator API, which had 300 free API credits per month. You can use the free API key with MailboxValidator CodeIgniter Email Validation Package after sign up.
Disclaimer: I am working at MailboxValidator.

Can't received inbound sms in plivo, it dosen't trigger codeigniter url

Recently I'm trying to received sms to plivo number. when i sent a sms from outsite plivo then it sent and plivo log status will show delivered. But i need to save data into database. It does not trigger to my controller function.
I already sent sms through another function. it sent and saved into my database but problem is, when anyone reply into this number.
controller function:
public function index()
{
// Sender's phone numer
$from_number = $this->input->get("From"); // $this->input->post("From"); dosen't work.
// Receiver's phone number - Plivo number
$to_number = $this->input->get("To"); // $this->input->post("To"); dosen't work.
// The SMS text message which was received
$text = $this->input->get("Text"); // $this->input->post("Text"); dosen't work.
// Output the text which was received to the log file.
// error_log("Message received - From: ".$from_number.", To: ".$to_number. ", Text: ".$text);
$arr = array("from" => $from_number, "to" => $to_number, "text" => $text);
$this->receive_model->add($arr);
}
Plivo application URL :
http://xxxxxxx.com/receive_sms
Message Method : GET
Message Method : POST // Dosen't work.
Codeigniter Config:
$config['allow_get_array'] = TRUE;
In plivo log status delivered.
any help?
Plivo started their Stop DND protocol a few days ago (i.e. June 2016). When a message comes back in response to a text from a Plivo phone number that says Stop... all further messages from Plivo are blocked.
The Plivo number sends a message and the recipient responds with Stop.
There is no do over. From then on, NO messages from Plivo will be delivered to that recipient as the recipients Stop message is interpreted as a request that all further messages be blocked.
Plivo offers no way of turning message delivery back on. That user has no way of correcting the Stop if sent in error. There is no do over.
All solutions lead to using a new different phone number.
A band aid... Incoming messages to that Plivo number still get received so there is the possibility of sending outgoing response messages from a second Plivo or other number. In theory looks OK BUT in reality this is at best a short term fix.
Most users naturally depend on sending messages by replying. Replying to the wrong new incoming number, instead of sending to the original phone number, just sets up another set of problems and issues to deal with. Not the least of those is what ever reason that caused the stop message in the 1st place or accidentally doing it again. Ends up like cutting your finger off 1/16th of an inch at a time.
At the first time i load plivo library class on the sms received controller, it was a problem. I just erase those line from controller and then it works fine.
We have to follow:
Plivo application always get data for codeigniter function. Codeigniter Config: $config['allow_get_array'] = TRUE; SMS received controller only load Codeigniter library file, nothing else.
It works for me.

WhatsApp chat-api registration process error

I am using WhatsApp Chat-API.
For registration process I follow the documentation as provided at
Documentation.
So for registration process I use the below code
$username = "mynumber";
$debug = true;
$r = new Registration($username, $debug);
$r->codeRequest('sms');
Now till here I get the msg for verification but the problem is how I can use code received on phone as next line of code is as given below
$code = '123456';// this is hard coded in documentation how i can use my verification code which i received on my phone
$r->codeRegister($code);
So after getting verification code how I use the above code to get login password?
What I did was to comment out $r->codeRegister($code) during the first run. Then I wait for WhatsApp to send the code. When I get the code on my phone, I comment out $r->codeRequest('sms') and uncomment$r->codeRegister($code); replacing$code` with the code the WhatsApp API sent.
It's a hackneyed way of doing this but it works.
Ideally, you should get $code from STDIN which waits for the user to type it in.

mobile phone's carrier information

We need to test the sms text notifications thru our project which is implemented in PHP. We have used the phone number combine with the carrier gateway. For example 7-11 Speakout (USA GSM) has a gateway #cingularme.com, so while send sms we are combining the number with the gateway as 9860112354##cingularme.com and sending this thru PHP's mail function.
Now wee need to test this on our mobile phones. However we are unabel to find the carrier gateway list for the same (Nokia 6300). Please advise.
Are you looking for a list of carrier email to SMS addresses? Such as ##tmomail.net?
If so, here's an exhaustive list:
http://www.mutube.com/projects/open-email-to-sms/gateway-list/
I had this problem also. The carrier gateway list, as posted out by another answer - is irrelevant to the device, but instead has to due with it's service provider. What you will need to do, is find the carrier - and then fetch it's email to SMS address, to build the e-mail address to send your message to. Such a list can be found on wikipedia.
To get the carrier and service provider of the cellular device, here is a simple function that will provide the cellphone's carrier name when provided with a celluar number:
<?php
// leave this blank - we may never implement an authentication key
$smsarc_API_key = '';
// enter the user's 10 digit cell phone number.
// example format: $smsarc_to = '5556667777';
$smsarc_number = '5192097991';
// lookup carrier
$ch = curl_init(); curl_setopt ($ch, CURLOPT_URL, 'http://www.smsarc.com/api-carrier-lookup.php?sa_number='.$smsarc_number); $AskApache_result = curl_exec ($ch); $smsarc_message_status = $AskApache_result; curl_close($ch);
// print the carrier lookup results
echo $smsarc_carrier;
?>
Developer API from their site:
http://www.smsarc.com/free-php-cell-phone-carrier-lookup/

Categories