I want to make a call from a web application(PHP/Laravel) to any mobile number from (purchased Nexmo Number). It's like a two-way communications call.
The scenario assumes in the web application(PHP/Laravel) page display the call driver options placed the call icon. Once customers click the call icon then call to driver number from (purchased Nexmo Number).
I have used this API to create a call.
$ncco = [
[
'action' => 'talk',
'voiceName' => 'Joey',
'text' => 'This is a text-to-speech test message.'
]
];
$call = new \Nexmo\Call\Call();
$call->setTo('XXXXXXXXXXXX')
->setFrom('XXXXXXXXXXXX')
->setNcco($ncco);
$response = $client->calls()->create($call);
echo $response->getId();
The Nexmo Voice API here one-way communication only working fine for me. For example, text to speech call works for me, the above voice API code run the call automatically reached to destination number from (purchased Nexmo Number).
Is anybody has done this scenario? when you click on the phone icon it will call customers + you can talk with customer using a web portal?
There are two ways to go about this.
Call Bridging
You can bridge two numbers together by having the system call you, and if you answer then call someone else to bridge them in. This can all be done on the server side much like what you have above, the NCCO just changes slightly.
$ncco = [
[
'action' => 'connect',
'endpoint' => [
[
'type' => 'phone',
'number' => DRIVER_NUMBER
]
]
]
];
$call = new \Nexmo\Call\Call();
$call->setTo(CUSTOMER_NUMBER)
->setFrom(VONAGE_NUMBER)
->setNcco($ncco);
$response = $client->calls()->create($call);
echo $response->getId();
The only real problem with this is the user experience. The user probably expects the call work like a real phone call (click the button, hear ringing, hope the driver connects). You would need to add some additional NCCO options like streaming a ring tone, checking to see if the other person declines the call or never answers and responding appropriately, etc, but it can be done by pushing some NCCOs around and watching the voice events.
In Browser/In App
The other option is our Client SDK, which is available for front-end JavaScript, iOS, and Android. This can be used to place a call from a browser or app, and do functionally the same but from within a dedicated interface. A short tutorial can be found at https://developer.nexmo.com/client-sdk/tutorials/app-to-phone/introduction/javascript.
Related
As per the official document, we can send push notification to multiple devices using a topic or device group. But the problem is it needs a common message and payload data for all devices.
I want to send different messages to all devices.
For example, below users should receive the following message on their
devices.
User Amit: Hello Amit, your request approved.
User Sandip: Hello Sandip, your request declined.
User Piyush: Hello Piyush, your request declined.
And so on..... to 200-300 users.
Is it possible to send this all messages in a single HTTP request using Firebase Cloud Messaging?
It is possible with the official Admin SDKs (see https://firebase.google.com/docs/cloud-messaging/send-message#send_a_batch_of_messages), but unfortunately, the REST API documentation doesn't include information on how to send batch requests (yet, at least I didn't find them so far), probably because it involves creating a special kind of multipart request and is not easy to set up.
So I would advise using an Admin SDK to do it. As I don't know how you've sent the messages in the past, please be warned that using an Admin SDK comes with some additional setup (e.g. creating/downloading a Service Account), compared to making "just" a cURL request.
So, if you don't have to use PHP, it's always wiser to use one of the official SDKs (see https://firebase.google.com/docs/admin/setup/)
If you do choose to stick with PHP, there is an unofficial Admin SDK for PHP at https://github.com/kreait/firebase-php that supports sending batch messages. (Disclaimer: I'm the maintainer of that SDK).
You can read more about it in the repo or specifically at https://firebase-php.readthedocs.io/en/latest/cloud-messaging.html#send-multiple-messages-at-once, but here is how it might look like for your situation if you decided to give the PHP SDK a try:
use Kreait\Firebase\Factory;
use Kreait\Firebase\Messaging\CloudMessage;
use Kreait\Firebase\Messaging\Notification;
use Kreait\Firebase\ServiceAccount;
$serviceAccount = ServiceAccount::fromJsonFile('/path/to/service_account.json');
$users = [
['name' => 'Amit', 'is_approved' => true, 'registration_token' => '...'],
['name' => 'Sandip', 'is_approved' => false, 'registration_token' => '...'],
['name' => 'Piyush', 'is_approved' => true, 'registration_token' => '...'],
// ...
];
$messages = [];
foreach ($users as $user) {
$statusText = $user['is_approved'] ? 'approved' : 'denied';
$messages[] = CloudMessage::withTarget('token', $user['registration_token'])
->withNotification([
'title' => "Your request was {$statusText}",
'body' => "Hello {$user['name']}! Your request was {$statusText}.",
]);
}
$messaging = (new Factory())
->withServiceAccount($serviceAccount)
->createMessaging();
$sendReport = $messaging->sendAll($messages);
echo 'Successful sends: '.$sendReport->successes()->count().PHP_EOL;
echo 'Failed sends: '.$sendReport->failures()->count().PHP_EOL;
I hope this helps!
I have the following code and it sends SMS notifications to my phone:
$notification = $twilio->notify->services($serviceSid)
->notifications->create([
'toBinding' => $batch,
'body' => $txt,
'statusCallback' => 'http://postb.in/b/jarblegarble' // <-- this doesn't work
]);
However, even though the sending works, I can't seem to figure out their callbacks.
I'm scouring through their docs and I can't find how to set the callback URL. I see some of their resources use "url" while others use "statusCallback" (heck, one seems to use "redirect"). That being said, I can't seem to post to postb.in using them -- there must be a way to check the status of my notification.
So it turns out I was wrong on two fronts.
1) The callback URL needs to be passed to your messaging service this way:
$notification = $twilio->notify->services($serviceSid)
->notifications->create([
'toBinding' => $bindings,
'body' => $txt,
'sms' => ['status_callback' => 'http://your_callback_url' ]
]);
2) postb.in wasn't working! I was testing the code above, after being assured by twilio support that it was valid, I decided to try and post to my own server and just capture the POSTed content. Sure enough, it was working as they suggested.
Edit: It wasn't clear to me at the time but the callback URL will be called for each SMS sent out for each status update. So that means queued, sent, and delivered. I initially thought that I'd just get a status update for the batch itself as I don't necessarily care for the status of up to 10,000 txt messages.
Your example passes the statusCallback parameter of the individual SMS service API to the universal notify API. This mixing won't work. The individual SMS service sets up a callback for that one particular message, which isn't efficient for batch sends. The universal notify API, in contrast, relies on web hooks, which are globally configured per service.
The simplest thing to do, in your case, is to use the individual SMS service API:
$message = $twilio->messages->create('+15551234567', [ 'body' => 'Hi',
'from' => '+15559876543',
'statusCallback' => 'http://postb.in/b/jarblegarble' ]);
To use the universal notify API, you'll need to set the PostWebhookUrl to the target URL when creating the notification service, and arrange for the code at that URL to handle onMessageSent messages. More at the "web hooks" URL above.
Caveat emptor: haven't tried any of this, and I haven't used Twilio in literally eight years, but the above is my theoretical understanding.
I am trying to implement following on Twilio, but not sure why I am not able to get it done correctly. I have initiated a call using standard Twilio procedures from twilio.device.connect. After a call is initiated, I am updating the call to new url in order to put it on hold.
$client = new Services_Twilio($accountSid, $authToken);
$call = $client->account->calls->get($call_sid);
$call->update(
array(
"Url" => "http://localhost/voice.xml",
"Method" => "POST",
)
);
Now here instead of putting end user on hold it just disconnects the call, and play music on my side. Why it is happening?
Twilio evangelist here.
I'd suggest checking to see if Twilio is logging any errors:
https://www.twilio.com/user/account/monitor/alerts
If you are trying to redirect Twilio to "http://localhost", thats not going to work because Twilio obviously does not know how to reach the localhost running on your own machine.
If you want to expose a web server running on your own local machine to the internet via a public URL check out an awesome tool called ngrok.
the reason is that after the <Play> tag in your
"http://localhost/voice.xml" file.. there is no further TwiML that gets executed.
The solution is to redirect the call back to its original state.
I am trying to write a PHP script that will allow me to do two things:
Allow users to use their Hotmail (I think its called 'Live' now?) account to authenticate themselves to a website
Retrieve an authenticated users contact list from Hotmail.
I have trawled the internet for the past 6 hours, looking for at least a working example that I can modify/extend to do the above two things. There are several dozens similar questions asked here on SO for example - NONE of the proffered answers work any more (admittedly, some of the questions were a few years old).
I tried the Microsoft site and downloaded the latest version of their API which seems to evolve at a rather alarming rate. I finally managed to track down an API which has not been deprecated (yet?).
I followed the instructions and when I attempted to authenticate, I was rewarded with the following mesage, for my efforts:
We're unable to complete your request
Windows Live ID is experiencing technical difficulties. Please try again later.
I immediately tried the online version of the demo and perhaps unsurprisingly, that worked like a charm.
As an aside, I managed to implement the same functionality for Yahoo and GMail, using their OPEN APIs, under an hour each. Now, it is possible that my unmitigated hatred of all things proprietary (sorry make that Microsoft), is causing me to lose the plot a little here.
Has anyone ACTUALLY (in 2012) managed to get a working sample in PHP that allows:
Hotmail (live?) user authentication
Hotmail user contact email retrieval
If you have, a code snippet, or a link to where I can find such a snippet would be very useful, as I have so far, wasted a whole afternoon trying to work the Microsoft Live API via PHP.
PS: No, I'm not interested in OpenInviter, its broken.
i wrote my own oauth library based around a single array for each service provider. this array contains all of the data required to perform authentication and retrieve user data. the array i use for msdn (ie. hotmail, outlook, xbox, msn) is:
$msdn = array
(
'oauth_version' => '2',
'oauth_method' => 'GET',
'redirect_user_params' => array
(
'url' => 'https://oauth.live.com/authorize',
'response_type' => 'code',
'http_params' => array
(
'url',
'client_id',
'redirect_uri',
'response_type',
'scope',
'state'
)
),
'obtain_access_token_params' => array
(
'url' => 'https://oauth.live.com/token',
'grant_type' => 'authorization_code',
'http_params' => array
(
'url',
'client_id',
'client_secret',
'code',
'grant_type',
'redirect_uri',
'scope'
)
),
'scope' => 'wl.signin wl.basic',
'obtain_user_data_params' => array
(
'url' => 'https://apis.live.net/v5.0/me',
'http_params' => array
(
'url',
'access_token',
'scope'
)
),
'client_id' => 'xxxxx', // = oauth_consumer_key in oauth 1.0 lingo
'client_secret' => 'xxxxxxxxxxxxxxx',
'readme_url' => 'http://msdn.microsoft.com/en-us/library/live/hh243647.aspx'
);
the parameters for each of the three oauth stages (ie "redirect user", "obtain access token" and "obtain user data") are in the http_params arrays. in the case of msdn these parameters end up in the query query string of the url that i send out with curl (since msdn only accepts GET, not POST).
i haven't tried retrieving the user's contact address book, but this would just be a case of extending the scope element with whatever extra information you require (documented here http://msdn.microsoft.com/en-us/library/live/hh243646.aspx). as you can see from the http_params arrays, the scope parameter is used in each of the three oauth stages.
Try out a Hotmail/MSN/Live import on the CloudSponge test drive to see if that's the user experience you're hoping for.
If it works for you, you can use our widget or our API. If you want to use the API, we have a PHP wrapper already written for your convenience.
Please confirm your callback url is with http:// if you only put www.domain.com then get this issue..
I need major help!
I am having troubles getting the Pubnub subscribe function to work with PHP! I can get the publish function to work, but not the subscribe function. I have copied some code straight from the Pubnub site, but I am not getting anything. Any help? Also, my PHP version is 5.2.*.
Code:
<?
include("Pubnub.php");
$pubnub = new Pubnub(
"not showing you", // PUBLISH_KEY
"not showing you", // SUBSCRIBE_KEY
"", // SECRET_KEY
false // SSL_ON?
);
$pubnub->subscribe(array(
'channel' => 'Chat',
'callback' => create_function(
'$message',
'var_dump($message); return true;'
)
));
?>
⚠️ ALERT: SDK has been upgraded ⚠️
New SDK URL: https://github.com/pubnub/php
You are asking about a way to use the Subscribe method within a web server like Apache using PHP as the dynamic processing language. Note that this is not a good practice and generally not necessary to do. You would not use the Subscribe({...}) method in a request/response.
The correct way to utilize the $pubnub->subscribe(...) method is in a long-lived PHP process, not involving a web server request-response model. Here are some examples that are confirmed to work:
https://github.com/pubnub/php
Note that each example is assumed to be in a solitary PHP process outside of a web server like Apache when using the Subscribe API in PHP. However! The Publish() API can be used anywhere, including an Apache web server.
Reading History w/ Apache PHP
As an alternative you will be happy to take advantage of our HISTORY API. You can query messages in the Queue with this and receive messages. Here is an example PHP History API usage:
<?php
## Capture Publish and Subscribe Keys from Command Line
$publish_key = "YOUR_PUBLISH_KEY";
$subscribe_key = "YOUR_SUBSCRIBE_KEY";
## Require Pubnub API
require('../Pubnub.php');
## -----------------------------------------
## Create Pubnub Client API (INITIALIZATION)
## -----------------------------------------
$pubnub = new Pubnub( $publish_key, $subscribe_key );
## Get History
echo("Requesting History...\n");
$messages = $pubnub->history(array(
'channel' => 'hello_world', ## REQUIRED Channel to Send
'limit' => 100 ## OPTIONAL Limit Number of Messages
));
var_dump($messages); ## Prints Published Messages.
?>
The php subscribe function is broken and will be fixed in a new upcoming api, I talked with support recently about this and they gave me the this information.