Join an active Twilio Voice conference call from browser as Supervisor (Muted) and Coach (Whisper to agent) - twilio-api

I have implemented Twilio Conference call using Twilio JavaScript SDK and PHP. So far, the functionality that is working is:
Agent can make an outgoing call from browser to a mobile phone
Agent can receive an incoming call on browser from another phone
<?php
require_once './vendor/autoload.php';
use Twilio\TwiML\VoiceResponse;
use Twilio\Rest\Client;
$response = new VoiceResponse();
$dial = $response->dial('');
$dial->conference('first-conference-room',
['startConferenceOnEnter' => 'true', 'endConferenceOnExit' => 'true']);
$sid = getenv("TWILIO_ACCOUNT_SID");
$token = getenv("TWILIO_AUTH_TOKEN");
$twilio = new Client($sid, $token);
$twilio->conferences("first-conference-room")
->participants
->create($fromnumber,
$tonumber,[
"statusCallbackEvent" => ["ringing","initiated","answered","completed"],
"statusCallback" => "link-to-php-function-to-write-call-record-to-database",
"statusCallbackMethod" => "POST"
]);
return $response;
?>
Now, as a supervisor, once a conference call is established between the agent (using browser) and another phone number, I fetch and show the ongoing call's record with a button to join as a supervisor.
Any suggestion on what can be done so 3rd person can join the conference as supervisor or coach?
A separate question - Is a Twilio conference between three people (numbers) charged as two Twilio voice calls or one Twilio voice call with third person joining the conference for a smaller fee?

Your supervisor is also in a browser, so when you click the join button, I assume you are making a call with the Twilio Voice SDK and your TwiML App directs the webhook to your endpoint that runs the second block of code from your question.
When you want to coach a call, you actually want more than just muting. You want to be able to listen to the call, talk to the agent without the person on the other end hearing, or barge in and talk to both people in the conference. To do this you need to use the coach attribute of the <Conference> TwiML.
To use coach you need to get the SID of the agent's call leg. If the agent is placing the outbound call from the browser, then their SID will be the CallSid parameter that is sent to your webhook URL. If they are receiving the call, then their call SID is returned from the API call to create a participant in the conference.
Once you have the SID, in the webhook response for your agent you need to dial into the conference and add the coach attribute with the value of the agent's call SID.
$response = new VoiceResponse();
$dial = $response->dial('');
$dial->conference('first-conference-room', ['coach' => $agentCallSid ]);
echo $response;
A separate question - Is a Twilio conference between three people (numbers) charged as two Twilio voice calls or one Twilio voice call with third person joining the conference for a smaller fee?
Twilio charges per leg of call. Each connection between Twilio and a caller is a leg. So in this case, three people in a conference are three legs and are charged the conference rate per minute each.

Related

PayPal - received cancel but the transaction was succesfull

On an e-commerce site in the payment page I used the new js sdk from paypal.
When the user clicks on paypal button a popup appears and the user performs the transaction in the popup.
When the transaction is over the popup closes and a callback is called to do what is needed.
If the user manually closes the popup, a CANCEL event is emitted and the transaction is considered canceled.
The problem I'm having is that sometimes I see on the logs that I receive the CANCEL event (meaning that the user has closed the popup) but on PayPal account the transaction is succesfull and correctly payed...
Is it possible that the user closes the popup just before paypal sends the confirmation back or something like that? Anyone knows how this can be handled?
Using the JS SDK alone is for very simple use cases. For an ecommerce site of any importance, the JS SDK should be combined with the v2/checkout/orders API. This way orders are always captured from the server and recorded when successful, and things happening on the client side won't be relevant nor interfere with accurate payment tracking.
Your question doesn't give technical details for your current integration, but here's how to go about making a correct one from scratch:
Use the v2/checkout/orders API and make two routes (url paths) on your server, one for 'Create Order' and one for 'Capture Order'. You could use one of the (recently deprecated) Checkout-*-SDKs for the routes' API calls to PayPal, or your own HTTPS implementation of first getting an access token and then doing the call. Both of these routes should return/output only JSON data (no HTML or text). Inside the 2nd route, when the capture API is successful you should verify the amount was correct and store its resulting payment details in your database (particularly purchase_units[0].payments.captures[0].id, which is the PayPal transaction ID) and perform any necessary business logic (such as reserving product or sending an email) immediately before forwarding return JSON to the frontend caller. In the event of an error forward the JSON details of it as well, since the frontend must handle such cases.
Pair those 2 routes with this frontend approval flow: https://developer.paypal.com/demo/checkout/#/pattern/server . (If you need to send any additional data from the client to the server, such as an items array or selected options, add a body parameter to the fetch with a value that is a JSON string or object)

how to create a private channel with stream chat flutter sdk?

I have an ecommerce app created with flutter ( under development),,
so I heard about the Stream_chat_flutter SDK ,, It is a really simple and easy solution to deal with, So my question is I have a user and a seller in my app and I want to make channel conversation between the seller and this particular user so when this user want to send a message to this seller in this time the channel will be created and the seller will be notified and get the message , How can I implement this with your Sdk?
note: that the seller can be contacted by many users .
(I have a authentication system with firebase.)
Capture from the app
Capture from the app
Channels are unique either by specifying a channel ID or a list of members in the create request.
If you want a private one on one channel between one user and a seller, use this:
client.channel("messaging", extraData: {"members": ["user_id", "seller_id"]});
See here for more info.
You can specify as many members as needed to create a group chat.

PayPal REST API v2/checkout/orders does not redirect back after approval

I've never used PayPal before, it's not really popular here, and I'm confused by how the order and payment works. Can anyone explain it to me? I've read the documentation and I'm still confused.
To complete payer approval, use the approve link to redirect the
payer. The API caller has 3 hours (default setting, this which can be
changed by your account manager to 24/48/72 hours to accommodate your
use case) from the time the order is created, to redirect your payer.
Once redirected, the API caller has 3 hours for the payer to approve
the order and either authorize or capture the order.
I have created a working PHP curl call for this API in sandbox env according to the sample
https://developer.paypal.com/docs/api/orders/v2/#orders_create
The APIs I created before work like this:
Send a request to 3rd party payment
Get a response containing a checkout link
Redirect customer to link
Customer complete payment
3rd party send a request containing order and payment detail to a file/path on my server
My server receives the request and updates the order status/payment in my database
3rd party redirect the customer to my webpage
With PayPal, what I got so far is:
Send request containing order detail to /v2/checkout/orders
Get a response containing various links
Redirect my customer to the rel:approve checkout link
Log in to my sandbox customer account and pay using PayPal balance, click Continue
A popup message is shown: We're sending you back to xxx's Test Store to complete this purchase
The popup message is closed and I'm still at the same payment page with the Continue button as seen in the image
Send request containing order detail to /v2/checkout/orders
Get a response containing links
Redirect my customer to approve link
Step (3) is an old integration method, for websites using an old redirect-based flow. The preferred way to integrate PayPal uses no redirects. At all. Your website remains loaded in the background. Do the following:
Follow the Set up standard payments guide and make 2 routes on your server, one for 'Create Order' and one for 'Capture Order', documented here. Both routes should return only JSON data (no HTML or text). Inside the 2nd route, when the capture API is successful you should store its resulting payment details in your database (particularly purchase_units[0].payments.captures[0].id, which is the PayPal transaction ID) and perform any necessary business logic (such as sending confirmation emails or reserving product) immediately before forwarding your return JSON to the frontend caller.
Pair those 2 routes with the frontend approval flow: https://developer.paypal.com/demo/checkout/#/pattern/server
If, for some odd and inexplicable reason, you insist on using the legacy flow with a full page redirect instead of what I just described above, you must include a redirect_url in your orders creation request, so that PayPal has somewhere to return to after the order is approved. Immediately when the return happens, capture the order with an API call and show the success/failure result to the customer. If you want an intervening order review step before capture, you can do this, but you must also edit your initial order creation request to change the verbiage of the last button at PayPal from "Pay Now" to "Continue" so that the user is clicking on something that corresponds to what the next step will be. application_context.user_action needs to be continue for this change.
Capturing an order will return a v2/payments object which is the completed transaction with its own ID for accounting and refund purposes. (The order ID is only used during payer approval, and unimportant otherwise)
I had this issue too, and I eventually got a solution from the documentation.
You have to add application_context.return_url to your request.
Attached is an example in PHP:
$postData = [
"intent" => "CAPTURE",
"purchase_units" => $purchase_units,
"application_context" => [
"return_url" => "",
"cancel_url" => "",
],
];
You can make a whole lot of customisations to the PayPal Payment page by adding the Application Context option, For a full list of the possible customisations, you can check up the official documentation Application Context Documentation

Twilio project - modify caller ID name and number

I am trying to figure out a way to send a call to Twilio either using an API or something else (maybe even PSTN call in format: xxx-xxx-xxxx,, yyy-yyy-yyyy where xxx-xxx-xxxx is Twilio number and yyy-yyy-yyyy the “destination number”).
Then have the twilio “relay” that call, sending out pre-programmed business name and number as caller ID to the destination number.
Business case:
Company A is spinning off a different division. When calls are made on behalf of this division, the caller ID cannot say “Company A”. It must say “company B” with the designated #.
Ok to register a diff acc w Twilio for company B if needed.
I don't think that you can pass info like a templated phone number placeholder to Twilio, itself. However, I think that this case might be a good use of the Gateway pattern. Basically, with the Gateway pattern, you create an API that wraps around and adapts to Twilio, itself. Thus, your consumers call your API and they pass dynamic company names and phone numbers as parameters to your API, and your code in the gateway then marshalls that into the body a Twilio request as per Twilio's quick start docs.
Twilio developer evangelist here.
You can set a caller ID when making a phone call. But caller IDs are phone numbers, not text strings, so this is not possible to do. The name that shows up when you receive a call is the name that you set for the contact in your own phone's address book.
I would recommend that if company A starts splitting off and doing different business to company B to just get company A a new phone number.

Twilio Recording after call initiated

I'm currently using the Twilio API in order to implement a call-recording feature for my app. I'm wondering whether it is possible to accomplish the following scenario.
Person A calls Person B, connection between the two is established
Person A would like to start recording the phone call and pushes a recording button
Call ends, Person A receives recording
I have tried the following:
Connect the two users so that they can talk to each other (Successful)
Use the REST API to modify the live call and put the TwiML record verb.(ref https://www.twilio.com/docs/api/rest/change-call-state#example-1)
Been stuck on step 2, whenever I try to redirect at all it just disconnects the call. Is there a proper way to inject TwiML messages while the call is going on using the rest API?