Send SMS from Web (are there some providers for this)? - sms

I'd like to have something like what the app.net site has. You click a button and get the option to send a link to your phone via SMS (or email). What are some options for implementing the sms side of things, and are there services or open source packages that provide this?
Here's a random example from app.net . Click the "Get this App" button to see what I mean.
Something like this would even work for me Send link to Phone Where "saasSMS.com" is some service that handles the whole sms side of things. Ideally could either handle that via a link or via a form post (and it would redirect back to your site on success or something).
What I don't want: A drop down that makes you pick your carrier and some php page that tries to email you #vtext.com or similar. That is just not slick enough.

You can use the ViaNett HTTP API to send SMS messages worldwide without specifying the operator.
As long as your backend supports invoking HTTP requests it will work.
Here is an example written in PHP:
<?php
// Register here to get a username and password:
// http://www.vianett.com/en/free-demonstration-account
if (vianett_sendsms('username', 'password', 'example', '+4412345678', 'Hello world', $error)) {
echo 'Success!';
} else {
echo $error;
}
function vianett_sendsms($username, $password, $from, $to, $msg, &$response=null) {
$url = 'https://smsc.vianett.no/v3/send.ashx';
$data = array(
'user' => $username,
'pass' => $password,
'src' => $from,
'dst' => $to,
'msg' => $msg
);
$qs = http_build_query($data);
$response = file_get_contents($url.'?'.$qs);
return $response == '200|OK';
}

We're getting good results from http://www.twilio.com

For direct SMS, you can try contacting a service provider and make a contract with it. If its for small projects and the server is accessible, you could put a GPRS mobile phone or modem and send with it.

Related

How to get message after command in Telegram bot sdk Laravel?

I have some issue with Telegram SDK! As you see in photo below, I ask to enter Some title after user enters /addnotification commmand, here user should enter some title of notification, but I can't get it, because update gives me last message , which was command /addnotification! Please, help if someone knows the answer!
public function handle()
{
$telegram = new Api(Telegram::getAccessToken());
$update = Telegram::getWebhookUpdates();
$chat_id = $update->getMessage()->getChat()->getId();
$text= $update->getMessage()->getText();
$response = $telegram->sendMessage([
'chat_id' => $chat_id,
'text' => 'Пожалуйста введите событие или дело который вы хотели бы добавить.'
]);
// $messageId = $response->getMessageId();
$this->replyWithMessage(['text' => 'Поздравляем! Вы успешно добавили событие!!!']);
$this->replyWithMessage(['text' => 'Название - ' . $text]);
$this->replyWithMessage(['text' => 'Chat Id - ' . $chat_id]);
// $this->replyWithMessage(['text' => $messageId]);
}
}
Here after entering command user should enter some title and I want to get this title(message) , but update gives message which was command!
You are asking the user to input a name for your notification in the same handler - your user has not done any input yet. The library you are using is providing handlers only for commands, you should handle regular messages anywhere else and use some state machine to indicate what input you are waiting from a user or use input syntax like /addnotification *name*. Personally, I could recommend you using this library for Laravel - it's documented better and has more features then irazasyed's one.

How to find referer of redirect to oauth client's callback

I am having trouble setting up a generic oauth client (and can't find good material on google).
I have this as my route to receive the callback from the oauth process:
Route::get('/oauth/callback', function (Request $request) {
$http = new GuzzleHttp\Client;
$response = $http->post('https://www.wunderlist.com/oauth/access_token', [
'client_id' => 'xxxxxxxxxxxxxxx',
'client_secret' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
'code' => $request->code
]);
});
but in order to make it generic, I must be able to identify where the redirect came from.
something in the lines of
$service = App\Service::where(<field>, $request-><information about the referer>);
does Request contain any kind of information that can help me identify the source of the redirect? I looked at the object with dd() and couldn't find anything
You should use request()->headers->get('referer') to check the referrer url.
I managed to work around the problem by defining the callback url so that it contains a query parameter identifying the service.
This means that I tell the service to callback to /oauth/callback?service=XXX
and I find it in my services table like this:
$service = Service::where('slug', Input::get('service'))->firstOrFail();

Http request and response in codeigniter

I am currently working in codeigniter and I am new to this.
I was wondering how to retrieve the JSON values using API call .
Can anyone suggest me where should I start.
Many Thanks in advance
Pass your array of row to json_encode();example for method of controller is below
public function getUserList() {
header('Content-Type: application/json');
$query = $this->db->get('mytable');
if(count($query) > 0) {
$message = array('status' => 'true' , 'message' => 'Record get successfully' , 'data' => $return );
}else{
$message = array('status' => 'false' , 'message' => 'Record not found.' );
}
echo json_encode($message);
}
Codeigniter does not have an inbuilt HTTP method so you need to use other things in php to achieve this.
There are 2 ways, you can use cURL, but honestly... it's convoluted... but read this: http://php.net/manual/en/book.curl.php
Another method is using stream_context_create() http://php.net/manual/en/function.stream-context-create.php
I strongly suggest using this 2nd one as its much easier to work with (in context with curl..
Much of how you setup your request depends on the API you are referencing with and the kind of requests it allows: GET, POST ... and what kind of header information it requires you to send over as well do they require oAuth header?
There is no 1 bunch of code fits all, I had to create a full custom library to integrate codeigniter into Magento, it took many hours.

How do I specify the Twilio StatusCallBack URL when using the sendMessage method (versus the create method)?

The following code works perfectly...
$message = $client->account->sms_messages->create($twilio_number, $to, $body, array("StatusCallback" => "http://etc...));
...for text messages within the 160 character limit. The SMS is sent, and my server is contacted at the callback URL when the status changes.
However, this method doesn't facilitate concatenated messages or MMS. For those, the Twilio documentation gives an example of sendMessage. This code works...
$message = $client->account->messages->sendMessage($from, $to, $body, $mediaURL);
...but the fourth call parameter, formerly used for the StatusCallBack URL, is replaced by the Media URL.
The Twilio documentation page has an "Optional Parameters" section, in which StatusCallback is listed and explained, but there's no example of how to include it when using the sendMessage method shown above and in their sample code.
Is it possible to specify a callback using the sendMessage method, and if so, how is it done?
Twilio developer evangelist here.
You're right, the documentation does not show you how to use optional parameters with the sendMessage method. You can actually pass a 5th argument to the method with an array of options, like so:
$message = $client->account->messages->sendMessage($from, $to, $body, $mediaURL, array("StatusCallback" => "http://example.com/callback"));
If you have no media to add to the message, this would look like:
$message = $client->account->messages->sendMessage($from, $to, $body, null, array("StatusCallback" => "http://example.com/callback"));
You can also use the create method with an array of options, which might be neater:
$message = $client->account->messages->create(array(
"To" => $to,
"From" => $from,
"Body" => $body,
"StatusCallback" => "http://example.com/callback"
));
Hope this helps.

CakePHP email not sending but showing in debug mode

My CakePHP should send an email when a button is clicked, however it doesn't. Also, the email will be displayed as a flash message if I run it in debug mode: ($this->Email->delivery = 'debug';).
Note: Email is set up to set up to use PHP mail() function.
Code to call the email function:
$this->_sendUpdateEmail( $this->Auth->user('id'), $about_id );
Email function
function _sendUpdateEmail($from_user_id, $about_id) {
$fromUser = $this->User->read(null, $from_user_id);
$users = $this->User->find('all', array(
'conditions' => array('User.distribution =' => 1)
));
# loop to send email to all users who are marked as on the distribution list
for($i = 0, $size = sizeof($users); $i < $size; ++$i) {
$user = $users[$i]['User'];
$this->Email->from = $fromUser['User']['email'];
$this->Email->replyTo = $fromUser['User']['email'];
$this->Email->to = $user['email'];
$this->Email->subject = 'Test email';
$this->Email->template = 'update';
$this->Email->sendAs = 'both'; // both = html and text
$this->set('user', $user);
$this->set('about', $about_id);
$this->Email->send();
$this->Email->reset();
}
}
Any ideas as to why the emails show in debug mode but won't actually send?
I think the reason why my emails were not sending was because there was no mail server configured on the web server my CakePHP was running on so there was no way to route the emails. However, this meant they would show up in the debug because they were generated successfully, just not sent.
In the end, I ended up using my company's Exchange mail server using the SMTP settings.
Code to use SMTP to send CakePHP emails
$this->Email->smtpOptions = array(
'port'=>'25',
'timeout'=>'30',
'host' => '192.168.0.244',
);
// Other email code here, e.g. from and to etc...
$this->Email->delivery = 'smtp';
I think the issue here is that mail server is not set right Linux comes built in with mail sending functionality but not windows (no idea on mac). look into smtp options as u can easily setup smtp email sender on Windows
Setting up smtp windows - http://publib.boulder.ibm.com/infocenter/cqhelp/v7r1m2/index.jsp?topic=/com.ibm.rational.clearquest.webadmin.doc/topics/c_config_email_smtp_win.htm
and
http://book.cakephp.org/view/1290/Sending-A-Message-Using-SMTP

Resources