Twilio Conference - PHP - Not receiving statusCallback - php

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.

Related

Telegram Bot Login via PHP MadelineProto

I have a private Telegram Channel. My bot is added to this Channel as admin.
I have a Webservice (PHP) which receives event. I want to tell my bot to kick a user from the Channel on a specific event - without any user interaction.
I am using MadelineProto library, but it always/sometimes asks for a api_id/api_hash, which I need to enter manually.
How can I specify those values (settings?) so that I do not need any user interaction?
if (!file_exists('madeline.php')) {
copy('https://phar.madelineproto.xyz/madeline.php', 'madeline.php');
}
include 'madeline.php';
$settings = [
'app_info' => [
'api_id' => 'xxxxxx',
'api_hash' => 'xxxxxxx'
]
];
$MadelineProto = new \danog\MadelineProto\API('session');
$MadelineProto->updateSettings($settings);
$auth = $MadelineProto->botLogin($BOT_TOKEN);
//Get Channel/User, kick user logic, this works, but I need to enter app_id/app_hash manually.
It seems to work this way:
$settings['app_info']['api_id']=xxx;
$settings['app_info']['api_hash']='xxx';
$MadelineProto = new \danog\MadelineProto\API('session', $settings);

Twilio get conference SID when connecting to devices

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);

Zendesk php api create ticket without sending email to the user?

I am trying to create tickets on my Zendesk and that is working fine. However i do not want Zendesk to email the creator of the tickets (his or her email). Is this possible?
The idea is i have a contactForm widget on my site, i want the submits from this form to create tickets in my Zendesk.
Creating tickets is currently working using this code:
$zendesk = new zendesk(
$row->api_key,
$row->email_address,
$row->host_address,
$suffix = '.json',
$test = false
);
$arr = array(
"z_subject"=>"Offline Message",
"z_description"=> $r->contact_msg,
"z_recipient"=>$r->contact_email,
"z_name"=>$r->contact_name,
);
$create = json_encode(
array('ticket' => array(
'subject' => $arr['z_subject'],
'description' => $arr['z_description'],
'requester' => array('name' => $arr['z_name'],
'email' => $arr['z_requester']
))),
JSON_FORCE_OBJECT
);
$data = $zendesk->call("/tickets", $create, "POST");
Any ideas?
Totally possible! You need to add some conditions to the trigger "Notify requester of received request" in Zendesk - Trigger setting to prevent zendesk from sending email. For ex:
Ticket : Channel - Is Not - Webservice (API)
Ticket : Tags - Contains one of the following - "offline message"
You could use another API endpoint "Ticket Import" https://developer.zendesk.com/api-reference/ticketing/tickets/ticket_import/
It's do not send notifications

twitter api (php) - statuses/destroy - returns nothing

I am using the tmOAuth library.
With the new 1.1 API, the following is returning an error code 400 - but authentication was done (same authentication for statuses works)! The library I am using works fine for all calls, except this one!
$tmhOAuth->request(
'POST', $tmhOAuth->url('https://api.twitter.com/1.1/statuses/destroy/MYIDHERE.json'),
array(
'id' => MYIDHERE
)
);
The twitter API documentation states that you don't have to send the id in post - but this doesn't make any difference.
I have tested this today with two different libraries, and neither work.
Any suggestions - does anyone know if there is an issue with it??
According to your comment, you have tested this in two libraries for the 1.1 API.
You haven't tested it in this one though. Instructions here, although you seem to already have your credentials in hand.
This basically proves that the library you are using has the issue, not the twitter API. So either submit a bug report on github (how else are they to know?), or use another library like the one above.
The exact code required using the above library (and it works, I just tested it):
// Require the library file
require_once('TwitterAPIExchange.php');
// Set up your credentials
$settings = array(
'oauth_access_token' => "YOUR_TOKEN",
'oauth_access_token_secret' => "YOUR_TOKEN_SECRET",
'consumer_key' => "YOUR_CONSUMER_KEY",
'consumer_secret' => "YOUR_CONSUMER_SECRET"
);
// Put the correct ID in the URL
$url = 'https://api.twitter.com/1.1/statuses/destroy/YOURIDHERE.json';
// Set the request type
$requestMethod = 'POST';
// Set the post fields
$postfields = array('id' => 'YOURIDHERE');
// Make the request
$twitter = new TwitterAPIExchange($settings);
$json = $twitter->buildOauth($url, $requestMethod)
->setPostfields($postfields)
->performRequest();
// Dump the response
$result = json_decode($json);
var_dump($result);
If you're using the twitteroauth php library from Abraham Williams and trying to delete old tweets/retweets you need to construct the post() query as such:
$response = $connection->post('statuses/destroy/'.$tweetID, array()); //Curl url output = statuses/destroy/$tweetID.json

Twitter stream latest tweets not working

I am trying to show the latest tweets on a webpage, but I am unsure of how to do it as I am very new to the twitter api, but here is what I have thus far.
function my_streaming_callback($data, $length, $metrics) {
echo $data;
}
require '../tmhOAuth.php';
$tmhOAuth = new tmhOAuth(array(
'consumer_key' => 'key',
'consumer_secret' => 'secret',
'user_token' => 'token',
'user_secret' => 'secret',
));
$method = 'http://stream.twitter.com/1/statuses//show/:id.json';
//not sure where I am supposed to get the :id from?
$params = array(
//not sure what to put here, I would like to display the last 5 tweets
);
$tmhOAuth->streaming_request('POST', $method, $params, 'my_streaming_callback');
$tmhOAuth->pr($tmhOAuth);
I am using this https://github.com/themattharris/tmhOAuth to authenticate, and then interface with the twitter api, but I am finding it very confusing as all of this is very new to me.
So basically I would just like to try and get the latest tweets, any help would be GREATLY appreciated, as I need to get this done ASAP, thanx in advance! :)
Stream API returns you only the tweets posted after you connected. To get previous tweets you need to use general REST API method: http://dev.twitter.com/doc/get/statuses/show/:id
$tmhOAuth->request('GET', $tmhOAuth->url('1/statuses/show/$id'));
$tmhOAuth->pr(json_decode($tmhOAuth->response['response']));
where $id is the user's id.
If you wish you can use THIS beautiful jQuery plugin. It do the some thing as you require. For more information visit http://tweet.seaofclouds.com/

Categories