Realtime voice call with 2 person using nexmo/vonage - php

is it possible to do realtime voice call using nexmo/vonage with PHP or Javascript via web browser?
i used library called nexmo/laravel.
This sample code that i used:
$nexmo = Nexmo::calls()->create([
'to' => [[
'type' => 'phone',
'number' => '855969818674'
]],
'from' => [
'type' => 'phone',
'number' => '63282711511'
],
'answer_url' => ['https://gist.githubusercontent.com/jazz7381/d245a8f54ed318ac2cb68152929ec118/raw/6a63a20d7b1b288a84830800ab1813ebb7bac70c/ncco.json'],
'event_url' => [backpack_url('call/event')]
]);
with that code i can send text-to-speech, but how can i do realtime voice conversation person to person?

From the code you shared above, it looks like you might not have instantiated a client instance of the Nexmo PHP SDK, which is necessary to do so. You make an outbound call with an instantiated and authenticated client.
For example, first instantiate a client with the following, supplying the file path to your private key file, your application ID, your API key and your API secret. You can obtain all of those from the Dashboard
$basic = new \Nexmo\Client\Credentials\Basic('key', 'secret');
$keypair = new \Nexmo\Client\Credentials\Keypair(
file_get_contents((NEXMO_APPLICATION_PRIVATE_KEY_PATH),
NEXMO_APPLICATION_ID
);
$client = new \Nexmo\Client(new \Nexmo\Client\Credentials\Container($basic, $keypair));
Then, once you have a credentialed client, you can then invoke the $client->calls() methods on it. For example:
$client->calls()->create([
'to' => [[
'type' => 'phone',
'number' => '14843331234'
]],
'from' => [
'type' => 'phone',
'number' => '14843335555'
],
'answer_url' => ['https://example.com/answer'],
'event_url' => ['https://example.com/event'],
]);
You can find more information on using the PHP SDK on GitHub. You can also find code snippets, tutorials, and more instructions on our developer portal.

Related

How to create an event in a "Group Calendar" using MS Graph API (PHP plugin)

How to create an event in a "Group Calendar" using the MS Graph APIs?
This is only possible using delegated permission from a Work or School Account.
Would you please share the code to achieve that (using the PHP - new Graph())?
Is it possible to do it completely silently, or login or consent pop-ups are involved?
HideAndSeek says he did it in the post: Microsoft Graph API: Group Calendar Events created by API are not sent to users Calendar but he does not share the code or explained how he did it.
Thanks
To use APIs that only support delegated permissions, authentication + user consent is required. Below is a code sample assuming the access token variable is acquired with delegated permissions. I am using MS Graph PHP SDK
$accessToken = 'eyJ0...';
$graph = new Graph();
$graph->setAccessToken($accessToken);
$attendees = [];
array_push($attendees, [
'emailAddress' => [
'address' => 'user#domain.com',
'name' => 'Name'
],
'type' => 'required'
]);
$newEvent = [
'subject' => 'Sample Event Subject',
'attendees' => $attendees,
'start' => [
'dateTime' => '2021-05-12T22:00:00',
'timeZone' => 'Pacific Standard Time'
],
'end' => [
'dateTime' => '2021-05-12T23:00:00',
'timeZone' => 'Pacific Standard Time'
],
'body' => [
"contentType" => "HTML",
"content" => "Chat about new hire"
]
];
$response = $graph->createRequest('POST', '/groups/group-id/calendar/events')
->attachBody($newEvent)
->setReturnType(Model\Event::class)
->execute();
echo "Created event - {$response->getSubject()}.";
Here is a complete example that will help you get started. The Guide is here

Discord API / Restcord : Create private channel

I'm trying to create private channels on Discord using Restcord, a PHP library that is very closely mapped to the Discord API.
Currently, I have managed to create voice channels, but all users on the server are able to see and join the channels. How can I make the channels so they are only available when invited ?
My current test code is :
$discord = new \RestCord\DiscordClient(['token' => config('services.discord.bot_token')]);
$channel = $discord->guild->createGuildChannel([
'guild.id' => config('services.discord.guild_id'),
'name' => 'lobby_' . uniqid(),
'type' => 2, // Voice
'permission_overwrites' => [
],
]);
$invitation = $discord->channel->createChannelInvite([
'channel.id' => $channel->id,
]);
return "https://discordapp.com/invite/{$invitation->code}";
Thanks in advance, any help is much appreciated, either with Restcord or directly using the API.
You need to use the permission_overwrites field. This fields accepts arrays of the overwrite object kind.
Example:
$discord = new \RestCord\DiscordClient(['token' => <token>]);
$channel = $discord->guild->createGuildChannel([
'guild.id' => config(<your guild ID>),
'name' => '<channel name>',
'type' => 2, // Voice
'permission_overwrites' => [
'id' => <role OR user id>,
'type' => 'role' (if id is role) OR 'user' (if id is single user),
'allow' => <permission ID for allowed permissions>,
'deny' => <permissions ID for denied permissions>
]
]);
Note that if you'd leave "allow" and "deny" as 0 (default value), the role/user with id 'id' would have the same permissions as otherwise defined server-wide. To get the permissions ID for a certain set of permissions, use a Discord Permission Calculator like this one (here the ID is called permission number).
Hope it helps!

Mailchimp create campaign with DrewM PHP wrapper

How do I create a campaign using this wrapper and pass parameters? Ive searched the internet and the documentation but their isn't enough information or example code
$mc->post('campaigns');
just returns an error. Thanks in advance.
Assuming you've authenticated, etc., you can just add in your parameters like the Mailchimp docs show:
$result = $MailChimp->post("campaigns", [
'type' => 'regular',
'recipients' => ['list_id' => 'xxx'],
'settings' => ['subject_line' => 'Your Purchase Receipt',
'reply_to' => 'orders#example.com',
'from_name' => 'Customer Service']
]);
The wrapper doesn't really do anything; it just provides a standard way to pass these arrays to Mailchimp.

Mailchimp verify subscriber email first

I use Laravel 5 to develop an app and I use Mailchimp for adding subscription. I use Mailchimp v.3 . I can make a list using this code:
$mailchimp = new Mailchimp(xxxxxxxxxxxx-xx);
$contact = [
'company' => $request['campaign'],
'address1' => $request['address'],
'city' => $request['city'],
'state' => $candidate->userCandidate->state,
'zip' => $request['zip'],
'country' => $request['country'],
'phone' => $request['phone'],
];
$campaign_details = [
'from_name' => $request['from_name'],
'from_email' => $request['from_email'],
'subject' => $request['remind_text'],
'language' => 'English'
];
$data = [
'name' => Auth::user()->name . ' Campaign',
'contact' => $contact,
'permission_reminder' => $request['remind_text'],
'campaign_defaults' => $campaign_details,
'notify_on_subscribe' => $request['from_email'],
'notify_on_unsubscribe' => $request['from_email'],
'email_type_option' => false,
'visibility' => $request['visibility'],
];
$list = $mailchimp->post('lists', $data);
I use this library drewm/mailchimp. My code on subscribing is this:
$mailchimp = new Mailchimp($api_key);
$subscriber = [
'email_type' => 'html',
'email_address' => $email,
'language' => 'English',
'status' => 'subscribed',
'merge_fields' => ['zip' => $zip]
];
$result = $mailchimp->post('lists/' . $list_id . '/members', $subscriber);
And I can successfully subscribe it. This is my question how to verify an email first before will be recorded on mailchimp list to avoid spammer. I read on mailchimp that they have DOUBLE OPT-IN method but it is only available if you use their form.
My solution is to email first on subscriber and create a link for verifying and this solution can take time. Is there another solution on this? Does Mailchimp have method to acquire this?
I don't have any idea on Mailchimp API. However, you just have to set up an email validation flow first. In this way, all emails will not be considered as "spam" in your records. Then you're free to do any email tasks without worrying if it is valid or not.
The quick answer to your question is to set the status to "pending" instead of "subscribed", but you should check out MailChimp's docs on managing subscribers with API v3 for more details.
MailboxValidator does have an easy import feature to grab your list from MailChimp for email validation purposes. Then it automatically updates your MailChimp list once the validation process is done.
https://www.mailboxvalidator.com/resources/articles/how-to-import-email-list-from-mailchimp/

Is it possible to add a subdomain to Route53 using the AWS PHP SDK?

I am working on a project where we will be creating both subdomains as well as domains in Route53. We are hoping that there is a way to do this programmatically. The SDK for PHP documentation seems a little light, but it appears that createHostedZone can be used to create a domain or subdomain record and that changeResourceRecordSets can be used to create the DNS records necessary. Does anyone have examples of how to actually accomplish this?
Yes, this is possible using the changeResourceRecordSets call, as you already indicated. But it is a bit clumsy since you have to structure it like a batch even if you're changing/creating only one record, and even creations are changes. Here is a full example, without a credentials method:
<?php
// Include the SDK using the Composer autoloader
require 'vendor/autoload.php';
use Aws\Route53\Route53Client;
use Aws\Common\Credentials\Credentials;
$client = Route53Client::factory(array(
'credentials' => $credentials
));
$result = $client->changeResourceRecordSets(array(
// HostedZoneId is required
'HostedZoneId' => 'Z2ABCD1234EFGH',
// ChangeBatch is required
'ChangeBatch' => array(
'Comment' => 'string',
// Changes is required
'Changes' => array(
array(
// Action is required
'Action' => 'CREATE',
// ResourceRecordSet is required
'ResourceRecordSet' => array(
// Name is required
'Name' => 'myserver.mydomain.com.',
// Type is required
'Type' => 'A',
'TTL' => 600,
'ResourceRecords' => array(
array(
// Value is required
'Value' => '12.34.56.78',
),
),
),
),
),
),
));
The documentation of this method can be found here. You'll want to take very careful note of the required fields as well as the possible values for others. For instance, the name field must be a FQDN ending with a dot (.).
Also worth noting: You get no response back from the API after this call by default, i.e. there is no confirmation or transaction id. (Though it definitely gives errors back if something is wrong.) So that means that if you want your code to be bulletproof, you should write a Guzzle response handler AND you may want to wait a few seconds and then run a check that the new/changed record indeed exists.
Hope this helps!
Yes, I done using changeResourceRecordSets method.
<?php
require 'vendor/autoload.php';
use Aws\Route53\Route53Client;
use Aws\Exception\CredentialsException;
use Aws\Route53\Exception\Route53Exception;
//To build connection
try {
$client = Route53Client::factory(array(
'region' => 'string', //eg . us-east-1
'version' => 'date', // eg. latest or 2013-04-01
'credentials' => [
'key' => 'XXXXXXXXXXXXXXXXXXX', // eg. VSDFAJH6KXE7TXXXXXXXXXX
'secret' => 'XXXXXXXXXXXXXXXXXXXXXXX', //eg. XYZrnl/ejPEKyiME4dff45Pds54dfgr5XXXXXX
]
));
} catch (Exception $e) {
echo $e->getMessage();
}
/* Create sub domain */
try {
$dns = 'yourdomainname.com';
$HostedZoneId = 'XXXXXXXXXXXX'; // eg. A4Z9SD7DRE84I ( like 13 digit )
$name = 'test.yourdomainname.com.'; //eg. subdomain name you want to create
$ip = 'XX.XXXX.XX.XXX'; // aws domain Server ip address
$ttl = 300;
$recordType = 'CNAME';
$ResourceRecordsValue = array('Value' => $ip);
$client->changeResourceRecordSets([
'ChangeBatch' => [
'Changes' => [
[
'Action' => 'CREATE',
"ResourceRecordSet" => [
'Name' => $name,
'Type' => $recordType,
'TTL' => $ttl,
'ResourceRecords' => [
$ResourceRecordsValue
]
]
]
]
],
'HostedZoneId' => $HostedZoneId
]);
}
If you get any error please check into server error.log file. If you get error from SDK library then there is might PHP version not supported.
if you run this code from your local machine then you might get "SignatureDoesNotMatch" error then Make sure run this code into same (AWS)server environment.

Categories