Cloud service for outbound call messaging - api

I would like to integrate a service as. Apart of our product signin that will call the user to give them a code.
I can generate codes as mp3 without issue but I don't know of a service that can place the call and then play the mp3 to the user.
Any thoughts or feedback on this sort of app need?

Highly recommend Twilio Cloud Communication, it can be used to send the code via SMS or by a phone call.
Using PHP as an example, here is how it would look -
Text Message
<?php
// Get the Twilio PHP Library from http://twilio.com/docs/libraries
require "Services/Twilio.php";
//Random Code
$code = rand(pow(10, 6-1), pow(10, 6)-1);
// Set your Twilio Account settings
$AccountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
$AuthToken = "YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY";
//Initial Twilio instance
$client = new Services_Twilio($AccountSid, $AuthToken);
//Recipient number - must be +15555555555 format
$recipient = '+18882224444';
$caller_id = '+18008885555'; //Twilio phone number
//Send the message
$sms = $client->account->sms_messages->create(
$caller_id,
$recipient,
"Your activation code is: $code"
);
Phone Call
<?php
// Get the Twilio PHP Library from http://twilio.com/docs/libraries
require "Services/Twilio.php";
// Set your Twilio Account settings
$AccountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
$AuthToken = "YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY";
//Initial Twilio instance
$client = new Services_Twilio($AccountSid, $AuthToken);
$call = $client->account->calls->create(
'9991231234', // From a valid Twilio number
'8881231234', // Call this number
//When the call is connected, code at this URL will be executed
'/say-code.php'
);
say-code.php
<?php
// Get the Twilio PHP Library from http://twilio.com/docs/libraries
require "Services/Twilio.php";
// Random Code
$code = rand(pow(10, 6-1), pow(10, 6)-1);
// Generate TwiML - XML for Twilio
// This will execute when the caller is connected and use Text-To-Speech to
// play their activation code.
// You may also use an MP3 like so:
// $response->play('http://example.com/code.mp3');
$response = new Services_Twilio_Twiml();
$response->say("Your activation code is $code");
print $response;
There are a lot of other helper libraries out there to accomplish this with Twilio. Hope this helps!

I am wondering if something like Twilio Cloud Communications would work.

Related

Twillio , connect between 2 numbers

I am trying to achieve following functionality with twillio.js on client side and ASP.NET Mvc website at the backend.
I need to connect a call between real phone number of sales person and phone number of a potential client.
For example on button click , I need to call potential client , and in a case the client answered , i need to add to the call sales person (that is not using twillio number , using regular landline)
Is it possible to achieve with twillio ?
Karen, hello!
Were you able to achieve what you were looking for with Alex's suggestion of the Click to Call tutorial?
https://www.twilio.com/docs/tutorials/walkthrough/click-to-call/csharp/mvc
The above uses a web form and ajax to send the form asynchronously. Then we handle the POST from our web form and connect the call via the REST API.
/// <summary>
/// Handle a POST from our web form and connect a call via REST API
/// </summary>
[HttpPost]
public ActionResult Call(Contact contact)
{
if (!ModelState.IsValid)
{
return Json(new { success = false, message = (ModelState.Values.First()).Errors.First().ErrorMessage, });
}
var twilioNumber = ConfigurationManager.AppSettings["TwilioNumber"];
// The following line is how you should get the absolute Uri in an internet faced
// server or a production environment
// var handlerUri = Url.Action("Connect", "Call", null, Request.Url.Scheme);
// this line allow us to get the absolute Uri in a local computer using a secure instrospectable
// service like ngrok ;)
var handlerUri = GetTestUri();
_twilioService.CallToNumber(twilioNumber, contact.Phone.Replace(" ", ""), handlerUri);
return Json(new { success = true, message = "Phone call incoming!"});
}
Please let me know if this is helpful for your use case.

How do you configure a client to auto-answer within vLine?

What is the correct method for setting a client to auto answer with the vLine API for WebRTC calls?
Looking at your comment, it looks like you have figured this out. But for completeness and for future reference I will go ahead and answer.
To auto answer a call, all you have to do is call MediaSession.start() when an incoming call comes in, instead of throwing a prompt to the user.
Here is an example snippet:
client.on('add:mediaSession', onAddMediaSession, self);
// Handle new media sessions
onAddMediaSession(event){
var mediaSession = event.target;
mediaSession.on('enterState:incoming', onIncoming, self);
},
// Handle new incoming calls and autoAccept
onIncoming(event){
var mediaSession = event.target;
// Auto Accept call instead of a prompt
mediaSession.start();
}
Note that you can do this in your code even if you are using the UI Widgets.

paypal PPAPIService new SDK

Concerning the new Paypal SDK, there is almost no useful example code, and the Internet is littered with examples of the old SDK. My question concerns making an API request for a third party paypal account for which i have obtained the token and secretToken through the permissions API.
In attempting to construct a PPAPIService object, where is the list of possible sevice names?
ie: $this->serviceName = $serviceName; (in the constructor) What is the string syntax for these?
In regards to the makeRequest method, how do I define the $apiMethod variable, and what is the format of the $params variable? What are the different parameters?
A simple example of how to just obtain the account balance of the authorized third party account would be extremely helpful.
I am using PHP.
from the PPAPIService.php file:
class PPAPIService
{
public $endpoint;
public $serviceName;
private $logger;
public function __construct($serviceName = "")
{
$this->serviceName = $serviceName; //is there ANY documentation about the syntax and types of service names?
$config = PPConfigManager::getInstance();
$this->endpoint = $config->get('service.EndPoint');
$this->logger = new PPLoggingManager(__CLASS__);
}
public function setServiceName($serviceName)
{
$this->serviceName = $serviceName;
}
public function makeRequest($apiMethod, $params, $apiUsername = null, $accessToken = null, $tokenSecret = null)
{
//what are the apiMethod types? syntax? and params? type.. options...??
}
}
Well, you do not have to create a PPAPIService object directly. Let's say you want to use the Invoicing SDK, here's what you would do
$invoiceService = new InvoiceService();
$invoiceService->setAccessToken($accessToken);
$invoiceService->setTokenSecret($tokenSecret);
$createInvoiceResponse = $invoiceService->CreateInvoice($createInvoiceRequest);
There's one service class (such as InvoiceService in this code snippet) per API that you would instantiate as per your needs. The API username/password are picked from the configuration file and the access token/token secret are set via code since they typically tend to be different for different invocations.
Which API are you trying to call, by the way?
To answer on your other concern, the new PayPal SDK's have all the required samples bundled within the SDK itself. The SDK + Samples canbe downloaded from
https://www.x.com/developers/paypal/documentation-tools/paypal-sdk-index

successful paypal api call is not showing up in the sandbox

Hi I'm a little perplexed. I'm making a paypal api call with sandbox credentials. The return ACK is: success. When i go to either payer or business sandbox account no transactions have been processed. I debuged through and looks like i'm populating all the fields, plus i would think if some fields are missing the error would've been thrown. Here is the code I'm using.
.....
APIProfile apiProfile = ProfileFactory.createSignatureAPIProfile();
apiProfile.setAPIUsername(paypalAccount.getApiLogin());
apiProfile.setAPIPassword(paypalAccount.getApiPassword());
apiProfile.setSignature(paypalAccount.getApiSignature());
apiProfile.setEnvironment(paypalAccount.getApiEnvironment());
// caller
NVPCallerServices callerServices = new NVPCallerServices();
callerServices.setAPIProfile(apiProfile);
// encoder
NVPEncoder encoder = new NVPEncoder();
encoder.add(METHOD, METHOD_VALUE);
encoder.add(RETURNURL, paypalAccount.getReturnUrl());
encoder.add(CANCELURL, paypalAccount.getCancelUrl());
encoder.add(CURRENCYCODE, CURRENCYCODE_VALUE);
encoder.add(PAYMENTACTION, PAYMENTACTION_VALUE);
encoder.add(AMT, payment.getPaymentOrder().getPrice().toString());
encoder.add(L_NAME0, L_NAME0_VALUE);
encoder.add(L_AMT0, payment.getPaymentOrder().getPrice().toString());
// call
String NVPRequest = encoder.encode();
String NVPResponse = callerServices.call(NVPRequest);
NVPDecoder decoder = new NVPDecoder();
decoder.decode(NVPResponse);
String ack = decoder.get(ACK);
payment.setPaymentTransaction(decoder.get(TOKEN));
......
Any help would be awesome!
If you are using express checkout you need to make 3 calls:
SetExpressCheckout (response with a token)
GetExpressCheckout
DoExpressCheckout
Once ‘DoExpressCheckout’ passes you should be able to see a transaction logged in your sandbox buyer and merchant accounts.
Have a look at: https://www.x.com/devzone/excerpts/chapter-2-express-checkout

Facebook Application building. How do I do a simple API call?

I have 4.5 years experience as a professional PHP developer, I have loads of experience with session handling, etc.
I am wanting to learn how to build Facebook applications. I have gone through the process of downloading the Facebook Developer application, I have used to it Create an App, I have set the canvas URL to where the app is hosted.
I can successfully "install" the app using a Facebook user account, and I can successfully access it. I have noted that when the app is loaded, a whole string of data gets passed to it, with parameter names like fb_sig_user and fb_sig_session_key. Currently, I am doing nothing with these parameters.
On the application end, obviously I am supposed to create a Facebook object by using my own APP ID key and SECRET key, which I have done.
But I can't seem to figure out how to start making API calls from my application back to Facebook.
How do I, at this point, just do something simple like get the person's name and display it to them?
Eg, how do I:
$first_name = $facebook->getUserFirstName();
.. do something like that?
I just want to do a simple test to ensure the API stuff is working.
Any help would be appreciated. Thanks.
The Facebook PHP SDK would probably be your first stop, with some example code as a close runner up.
Making API calls with the Facebook SDK set up alright is as easy as;
$me = $facebook->api('/me'); // Returns array containing data for currently logged in user depending on given permissions
or
$my_friends = $facebook->api('/me/friends'); // Returns array containing information on friends of currently logged in user
and even
$my_profile_img = $facebook->api('/me/picture'); // Returns a string containing URL to users profile picture.
Also, everything within the open graph has unique id's that you can plug in instead of me in /me.
For further and more in-depth description of the Open Graph, I suggest going to the official Graph API Overview page.
Quite easy and fun to work with once you get it set up - albeit a bit slow.
Update:
In order to get the Facebook cookie and set up a session from it I did:
$cookie = get_facebook_cookie($fbconfig['appid'], $fbconfig['secret']);
function get_facebook_cookie($app_id, $application_secret) {
$args = array();
parse_str(trim($_COOKIE['fbs_' . $app_id], '\\"'), $args);
ksort($args);
$payload = '';
foreach ($args as $key => $value) {
if ($key != 'sig') {
$payload .= $key . '=' . $value;
}
}
if (md5($payload . $application_secret) != $args['sig']) {
return null;
}
return $args;
}
if (isset($cookie)) {
$session = $facebook->getSession($cookie);
}
Then updated Facebook.php line 332 to be
public function getSession($passedCookie) {
and line 373 to be
$this->setSession($passedCookie, $write_cookie);
Lame hacking, but it worked for me at least