Twilio get conference SID when connecting to devices - php

Is there a way to get the conference SID when connecting the calls in PHP?
$twilio->account->calls->create(
$from,
to,
$twimlURL
);
Can't I get the conference ID after this call action?
Or maybe set the conference SID on the Twiml. Is this possible?

Twilio developer evangelist here.
When you create a call through the REST API like that, it is not yet associated with a conference. I assume the $twimlURL that you send returns <Dial><Conference>some conference name</Conference></Dial> and that is the time that the call is associated with the conference.
You can get the Conference SID by listing conferences using the REST API and filtering by the FriendlyName (the name you used in the TwiML) and by the status in-progress. Like this:
use Twilio\Rest\Client;
$sid = "your_account_sid";
$token = "your_auth_token";
$client = new Client($sid, $token);
$conferences = $client->conferences->read(
array("status" => "in-progress", "friendlyName" => "MyRoom")
);
foreach ($conferences as $conference) {
echo $conference->sid;
}
Let me know if that helps at all.

In Case someone is looking for a C# version
TwilioClient.Init(credentials.AccountSID, credentials.AuthToken);
ResourceSet<ConferenceResource> conferencesResources = await ConferenceResource.ReadAsync(status: "in-progress", friendlyName: "<your conference room name>");
ConferenceResource conference = conferencesResources.FirstOrDefault();
Console.WriteLine(conference.Sid);

Related

Use token from "sign in with apple" to query apple music api

Context
I am trying to make webservice that fetches the name and email from an users Apple account and place a Song or Artist in his library.
For adding a Song to the library I found this apple-music-api. library. To make requests on behalf of a user you need to request a user token with Apple MusicKit JS library.
For fetching the name and email of the user I use this oauth2 client that uses the signin with Apple functionality.
Problem
A Using the apple music kit... I can not query any user profile data. At least I cannot seem to find an example nor any documentation of this. Is there a possibility to get the user email and name using this route?
B Using the Sign in with Apple oauth flow I receive an access token which contains the name and email. But I cannot use the token to query the apple music api. It seems their scopes are limited to the name and email...and no scope for the music api or related seems to exist. Is there a possibility to get an user token that can be used on the music api?
C Are there any other possibilities to accomplish this without requiring the user to sign in twice on apple (once for the email and once for pushing the Song to his library)
What I tried for option B
// $leeway is needed for clock skew
Firebase\JWT\JWT::$leeway = 60;
$provider = new League\OAuth2\Client\Provider\Apple([
'clientId' => 'com.myapp.www',
'teamId' => 'team.id', // 1A234BFK46 https://developer.apple.com/account/#/membership/ (Team ID)
'keyFileId' => 'key.id', // 1ABC6523AA https://developer.apple.com/account/resources/authkeys/list (Key ID)
'keyFilePath' => dirname(__FILE__) . '/AuthKey_key.id.p8', // __DIR__ . '/AuthKey_1ABC6523AA.p8' -> Download key above
'redirectUri' => PLUGIN_URL . 'callback-apple-music.php',
]);
if (isset($_POST['code'])) {
if (empty($_POST['state']) || !isset($_COOKIE['apple-oauth2state']) || ($_POST['state'] !== $_SESSION['apple-oauth2state'])) {
unset($_COOKIE['apple-oauth2state']);
exit('Invalid state');
} else {
try {
// Try to get an access token (using the authorization code grant) via signin_with_apple
/** #var AppleAccessToken $token */
$token = $provider->getAccessToken('authorization_code', [
'code' => $_POST['code']
]);
$access_token = $token->getToken();
// create an client for api.music.apple
$tokenGenerator = new PouleR\AppleMusicAPI\AppleMusicAPITokenGenerator();
$jwtToken = $tokenGenerator->generateDeveloperToken(
'team.id',
'key.id',
dirname(__FILE__) .'/AuthKey_key.id.p8'
);
// create a developer token again
$curl = new \Symfony\Component\HttpClient\CurlHttpClient();
$client = new PouleR\AppleMusicAPI\APIClient($curl);
$client->setDeveloperToken($jwtToken);
$api = new PouleR\AppleMusicAPI\AppleMusicAPI($client);
$api->setMusicUserToken($access_token);
// This endpoint needs authorisation
$result = $api->getAllLibraryPlaylists(); //https://api.music.apple.com/v1/me/library/playlists?offset=0&limit=25
echo '<pre>';
print_r($result);
echo '</pre>';
// wp_redirect($redirect_url);
exit;
} catch (Exception $e) {
echo '<pre>';
print_r($e);
echo '</pre>';
}
}
}
The problem with the question is that these are three questions - and not telling which client.
Most commonly "login with" is only good for creating local accounts without much typing.
And it is quite likely intentional, that the oAuth2 scope is extremely limited for this purpose.
And I've looked it up ...one needs a "Music User Token":
https://developer.apple.com/documentation/applemusicapi/getting_keys_and_creating_tokens
And this token needs to be passed as HTTP header: 'Music-User-Token: [music user token]'.
Which means, that the user token may either originate from an iOS device (you'd need to expose eg. a REST API, so that it can be posted and then used by PHP as HTTP header, on the server-side): https://developer.apple.com/documentation/storekit/skcloudservicecontroller/2909079-requestusertoken (this only requires a login to your own API).
When running Apple MusicKit JS on the cient-side (browser), two logins may not be evitable:
https://developer.apple.com/documentation/musickitjs/musickit/musickitinstance/2992701-authorize
It makes no sense to use both of these flows within the same method(which also ignores the principle of single responsibility).

How to get Locations list in Google My Business API | PHP

How can I get locations list in Google My Business API. Where I retrieved account list but I can't figure out how to retrieve location.
Here is my code where I am getting accounts list
define('GOOGLE_CLIENT_ID', 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX');
define('GOOGLE_CLIENT_SECRET', 'XXXXXXXXXXXXX');
// Create Client Request to access Google API
$client = new Client();
$client->setApplicationName('my-app');
$client->setClientId(GOOGLE_CLIENT_ID);
$client->setClientSecret(GOOGLE_CLIENT_SECRET);
$client->setRedirectUri('https://example.com/callback');
$client->addScope('https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/business.manage');
$client->setAccessType('offline'); // offline access
$client->setIncludeGrantedScopes(true); // incremental auth
$client->setAccessToken($accessToken);
$service = new \Google_Service_MyBusinessAccountManagement($client);
$accounts = $service->accounts->listAccounts()->getAccounts(); // get accounts
To get google locations,
you can use this PHP My Business file to make things little easier.
First change you scope to ttps://www.googleapis.com/auth/plus.business.manage then include the file and create a object of Google_Service_MyBusiness with you client and then do like this.
$mybusinessService = new Google_Service_MyBusiness($client);
// Get the first account in the accounts array
$accounts = $mybusinessService->accounts;
$accountsList = $accounts->listAccounts()->getAccounts();
$account = $accountsList[0];
// Get the first location in the locations array
$locations = $mybusinessService->accounts_locations;
$locationsList = $locations->listAccountsLocations($account->name)->getLocations();
$location = $locationsList[0];
var_export($location);
With this process you can also able to get google reviews.
For more details check this Google Business API documentation.
Hope it can help
"It's correct!!!
I increase this at my code:
$optParams = array(
'readMask' => 'name',
);
$list_accounts_response = $my_business_account->accounts_locations->listAccountsLocations("accounts/114893266195214446586", $optParams);
var_dump($list_accounts_response);
Thank you.."
source : https://github.com/googleapis/google-api-php-client/issues/2213#issuecomment-1042785983

Twilio Conference - PHP - Not receiving statusCallback

I am using Twilio to set up conference calls. I need to make an announcement (play an MP3 file) in the conference but it appears the $twilio->conferences("CFxxxxxxx")->update requires the ConferenceSid (I would prefer to use the FriendlyName, but that doesn't work).
So, I added statusCallback to get the ConferenceSid at the start of the conference but it isn't sending a request. I'm guessing the fix is easy, but i can't figure out what it is.
$twilio = new Client($sid, $token);
$participant = $twilio->conferences("myFriendlyName",
array(
"statusCallbackEvent"=>"initiated",
"statusCallback"=>"https://example.com/wp-json/rec/v1/myroute/",
"statusCallbackMethod"=>"POST"))
->participants
->create(
"+15555555",
$participantphone,
array(
"record" => True,
"endConferenceOnExit" => False,
"recordingStatusCallbackEvent" => array("completed"),
"RecordingStatusCallback" => "https://example.com/wp-json/rec/v1/myroute/")
);
I receive RecordingStatusCallback, but not the statusCallback request.
Twilio developer evangelist here.
You're not getting the status callback because you aren't setting it for the new participant. In your example code the second parameter you pass to the conferences resource doesn't do anything.
Instead you should pass all of those parameters as options to the call to create the new participant.
$twilio = new Client($sid, $token);
$participant = $twilio->conferences("myFriendlyName")
->participants
->create(
"+15555555",
$participantphone,
array(
"record" => True,
"endConferenceOnExit" => False,
"recordingStatusCallbackEvent" => array("completed"),
"recordingStatusCallback" => "https://example.com/wp-json/rec/v1/myroute/"),
"statusCallbackEvent"=>"initiated",
"statusCallback"=>"https://example.com/wp-json/rec/v1/myroute/",
"statusCallbackMethod"=>"POST"
);
Let me know if that helps at all.

Twilio Pass conference name using session codeigniter

Hi guys I am having a problem with twilio currently setting an assignment to a worker and i need to pass the worker to the conference. My problem is that i cant use session to retrieve the id in the session and the id will be the conference name of the conference to be able to have a unique conference name for a worker.
This is my callback in twilio
This is my code to get the task. And the id will be passed on forward_queue_conference.
public function assignment()
{
id = $this->session->userdata('user_id');
$TaskAttributes = $_POST['TaskAttributes'];
$json = json_decode($TaskAttributes, true);
$this->Mytwilio->SetAssignment($json['from'], AFTERTALK, HTTP_BASE_URL."agent/call_controls/forward_queue_conference?data=".$id);
}
This is my code on forward_queue_conference to retrieve the pass data
public function forward_queue_conference()
{
roomName = $_GET['data'];
$this->Mytwilio->CallerToQueue($roomName);
}
MyTwilio is a library that i made for twilio functions.
function CallerToQueue($roomName)
{
$response = new Services_Twilio_Twiml;
$dial = $response->dial();
$dial->conference($roomName, array(
'startConferenceOnEnter' => 'true',
'endConferenceOnExit' => 'true',
'muted' => 'false',
'record' => 'record-from-start',
'waitUrl' => 'http://twimlets.com/holdmusic?Bucket=com.twilio.music.ambient',
));
print $response;
}
And this is my whole process my problem is that i cant get the session data to become the conference room.
Twilio developer evangelist here.
When Twilio makes a callback to a URL on your website, it does not share the same session as your logged in user. It is therefore impossible to get the current user ID from the session.
However, your workers have an ID in the Twilio system. And that ID is sent as part of the parameters for the webhook. So, I recommend using the WorkerSid as the conference room instead of your own ID. Or alternatively, you could map between your worker ID and the user ID in your system.

How can i get campaign's web id when campaign is created using API in Mailchimp?

I am using API version 1.3 of mailchimp to create Campaign programmatically in PHP.
I am using MCAPI class method campaignCreate() to create campaign. Campaign is created successfully and it returns campaign id in response which is string.
But i need Web id (integer value of campaign id) so that I can use it to open that campaign using link on my website.
For example: lets say I want to redirect user to this link - https://us8.admin.mailchimp.com/campaigns/show?id=941117 and for that i need id value as 941117 when new campaign is created.For now i am getting it as string like 6ae9ikag when new campaign is created using mailchimp API
Please let me know if anyone knows how to get campaign web id (integer value) using Mailchimp API in PHP
Thanks
I found an answer so wanted to share here.Hope it helps someone
I get campaign id as a string when createCampaign() method of MCAPI class is used.
You need to use below code to get web id (integer value of campaign id)
$filters['campaign_id'] = $campaign_id; // string value of campaign id
$campaign = $api->campaigns($filters);
$web_id = $campaign['data'][0]['web_id'];
This worked for me.
Thanks
<?php
/**
This Example shows how to create a basic campaign via the MCAPI class.
**/
require_once 'inc/MCAPI.class.php';
require_once 'inc/config.inc.php'; //contains apikey
$api = new MCAPI($apikey);
$type = 'regular';
$opts['list_id'] = '5ceacbda08';
$opts['subject'] = 'Test Newsletter Mail';
$opts['from_email'] = 'guna#test.com';
$opts['from_name'] = 'guna';
$opts['tracking']=array('opens' => true, 'html_clicks' => true, 'text_clicks' => false);
$opts['authenticate'] = true;
$opts['analytics'] = array('google'=>'my_google_analytics_key');
$opts['title'] = 'Test Newsletter Title';
$content = array('html'=>'Hello html content message',
'text' => 'text text text *|UNSUB|*'
);
$retval = $api->campaignCreate($type, $opts, $content);
if ($api->errorCode){
echo "Unable to Create New Campaign!";
echo "\n\tCode=".$api->errorCode;
echo "\n\tMsg=".$api->errorMessage."\n";
} else {
echo "New Campaign ID:".$retval."\n";
}
$retval = $api->campaignSendNow($retval);
?>
The web_id is returned by mailchimp when a call is made to the creation end point.
$mcResponce = $mailchimp_api->campaigns->create(...);
$web_id = $mcResponce['web_id'];
See the documentation.

Categories