Graph API: Transfer call to call queue - rest

In a Teams AutoAttendant you can forward the call to a Call Queue.
I am trying to achieve this same behavior with a Teams Bot.
An incoming call from the PSTN is answered by the bot.
The bot answers the call and plays a prompt.
After that the bot should transfer this call to a specific call queue!
I was able to transfer the call to a user without any trouble:
callbackUrl: process.env.WebserviceUrl + '/api/calls/notifications',
transferTarget: {
endpointType: 'default',
identity: {
user: {
id: '[User GUID]',
displayName: 'User Name'
},
}
}
Now I d'like to transfer the call to a Call Queue instead of a single user:
callbackUrl: process.env.WebserviceUrl + '/api/calls/notifications',
transferTarget: {
endpointType: 'default',
identity: {
applicationInstance: {
id: '[Application instance GUID]',
displayName: 'Call Queue XY'
},
}
}
I tried applicationInstance and application as key. I also tried with optional tenantId in the identity. Received Error is always:
403 - Forbidden
{
error: {
code: '7505',
message: 'Request authorization tenant mismatch.',
innerError: {
date: '2020-06-24T03:37:16',
'request-id': '5da7621f-dd3f-494e-a057-733e60c59bdb'
}
}
}
There is only one Tenant involved. So access key is obtained with the same tenantId as the Tenant the user and call queue are part of.
Maybe someone has a hint and can help me find the right way to achieve this.
EDIT:
Redirecting an unanswered Call to the same Call Queue works without any troubles!
If there is no way to Transfer an active call to the Queue, we will try to find a way for our use case with redirecting.

Related

Capturing Paypal payment always fails with PAYER_ACTION_REQUIRED in production

Several weeks ago, we started seeing failed payments with our old Paypal Express integration without making any changes to it. They did not fail 100% but maybe 80%-90%. It seemed to fail arbitrarily.
We followed the upgrade path for the new Checkout integration, but kept seeing the same errors.
Finally we went all in on the new Standard (not Advanced!) Checkout integration using the Orders v2 API, replacing the old Payments V1 API. But that did not change anything either.
Side note: All of the integrations (old, updated, new) work totally fine in Sandbox.
But in production, almost every capture request fails with a PAYER_ACTION_REQUIRED error.
Here are the the steps:
User clicks on the checkout with paypal button.
The button's createOrder() method calls our server and we create an order with a POST to https://api.paypal.com/v2/checkout/orders, with the following response:
{
id: '1KC867444K565180X',
status: 'CREATED',
links: [
{
href: 'https://api.paypal.com/v2/checkout/orders/1KC867444K565180X',
rel: 'self',
method: 'GET'
},
{
href: 'https://www.paypal.com/checkoutnow?token=1KC867444K565180X',
rel: 'approve',
method: 'GET'
},
{
href: 'https://api.paypal.com/v2/checkout/orders/1KC867444K565180X',
rel: 'update',
method: 'PATCH'
},
{
href: 'https://api.paypal.com/v2/checkout/orders/1KC867444K565180X/capture',
rel: 'capture',
method: 'POST'
}
]
}
We do not redirect to the approve URL (since the button should handle it on the frontend, right?). So we just hand the ID back to the button's createOrder() method.
The onApprove() callback then calls our server again with the orderId and the paymentId. We do not capture the payment yet. Instead, we fetch the details to get the shipping address. After calculating the shipping costs, we PATCH the order. Then we fetch details again and verify that all changes have been applied correctly - which ist the case.
Side note: When fetching details after creating the order (so after it went through the buttons onApprove() callback, and right before capturing), there is no more approve link listed:
{
id: '1KC867444K565180X',
intent: 'CAPTURE',
status: 'APPROVED',
purchase_units: [
{
//...
}
],
payer: {
//...
},
create_time: '2022-07-14T14:41:16Z',
links: [
{
href: 'https://api.paypal.com/v2/checkout/orders/1KC867444K565180X',
rel: 'self',
method: 'GET'
},
{
href: 'https://api.paypal.com/v2/checkout/orders/1KC867444K565180X',
rel: 'update',
method: 'PATCH'
},
{
href: 'https://api.paypal.com/v2/checkout/orders/1KC867444K565180X/capture',
rel: 'capture',
method: 'POST'
}
]
}
Up until now, sandbox and production behave excatly the same. But when we now try to capture the payment, sandbox works fine, but production returns this:
{
name: 'UNPROCESSABLE_ENTITY',
details: [
{
issue: 'PAYER_ACTION_REQUIRED',
description: 'Payer needs to perform the following action before proceeding with payment.'
}
],
message: 'The requested action could not be performed, semantically incorrect, or failed business validation.',
debug_id: '160e81e8cc53f',
links: [
{
href: 'https://developer.paypal.com/docs/api/orders/v2/#error-PAYER_ACTION_REQUIRED',
rel: 'information_link',
method: 'GET'
}
]
}
We completely ran out of ideas what to do with this message. The docs suggest that "The order requires an action from the payer (e.g. 3DS authentication). Redirect the payer to the "rel":"payer-action" HATEOAS link returned as part of the response prior to authorizing or capturing the order." - but there is no such link. Plus, the order status is already APPROVED.
Any help would be highly appreciated.
It's probably related to having patched the order before capture, requiring re-approval.
Adapt the error handling code in this demo to also call actions.restart() when the issue is PAYER_ACTION_REQUIRED .
Essentially,
if (errorDetail && ['INSTRUMENT_DECLINED', 'PAYER_ACTION_REQUIRED'].includes(errorDetail.issue) ) {
Alternatively, instead of the button JS you can use the rel:approve href from the original order creation and redirect to that.
this error is due to the EBA PSD2.0 regulation. any order is paid through credit card issued from EMEA region, and the capture amount is higher than the create order amount, it will be declined with the error code. here's the PayPal change about the over capture:
https://www.paypal.com/ae/smarthelp/article/FAQ4645

STMP client from email js not working on aws amplify

I am trying to set up an emailing system for users on my website. I am using nextJS and have an api endpoint to send emails. To send the emails I am using emailJS and sending the email to myself with a custom body. Here is the code for my email.js file:
import { SMTPClient } from 'emailjs';
export default function handler(req, res) {
const {body, subject}=req.body;
// console.log(process.env)
const client = new SMTPClient({
user: "test#gmail.com",
password: "passward",
host: 'smtp.gmail.com',
ssl:true
});
try{
client.send(
{
text: `${body}`,
from: "test#gmail.com",
to: "test#gmail.com",
subject: `${subject}`,
}
)
}
catch (e) {
res.status(400).end(JSON.stringify({ message: e.message }))
return;
}
res.status(200).end(JSON.stringify({ message:'Mail sending' }))
}
The code works when I use it on localhost but it does not work when I deploy to amplify. When I try to make a post request on amplify I get status 200 with the {"message":"Mail sending"}. However, the gmail account never gets the email. I do not get an error message. I do not have 2 step verification on and have allowed less secure apps, but still no emails are being sent. I would really appreciate any help.
The emailjs library utilizes a queuing system for sending emails. This means that the send method adds the email to the queue and sends it at a later time. This can cause issues when using the send method within a lambda function, as the function may close before the email has been sent. To ensure that the email is sent before the lambda function closes, you can use the sendAsync method instead. This method returns a promise that will be resolved when the email has been successfully sent.
To send an email using the sendAsync method, you can do the following:
await client.sendAsync(
{
text: `${body}`,
from: "test#gmail.com",
to: "test#gmail.com",
subject: `${subject}`,
}
)

Implementing Handover protocol for facebook chatbot throws error

My primary receiver is my dialogflow chatbot and my second one is the page inbox. I want to switch from the chatbot to the inbox by implementing:
request({
uri: 'https://graph.facebook.com/v3.2/me/pass_thread_control',
qs: {'access_token': 'pageAccessToken'},
method: 'POST',
json: {
recipient: {
id: 'userIdFromRequest'
},
target_app_id: 'pageInboxAppId'
},
}, (error: any, response: any, body: any) => {
console.log('BODY PASS THREAD CONTROL: ', body);
});
But I'm getting this error:
(#10) Only available to Primary and Secondary Receivers
When I try to get the secondary receivers:
request({
uri: 'https://graph.facebook.com/v3.2/me/secondary_receivers?fields=id,name&access_token=<page-access-token>',
qs: {'access_token': <page-access-token>},
method: 'GET',
}, (error: any, response: any, body: any) => {
console.log('BODY SECONDARY RECEIVERS: ', body);
});
I will get this error:
(#10) Only Main Receiver can call this API
But my chatbot IS the main receiver. I set in in page settings --> messenger platform.
I found out that this used to be a facebook bug, but it should have been fixed now.
Does someone has an idea what I'm doing wrong?
UPDATE
The app_roles parameter is missing in the web hook request. May it could have something to do with it?
Another mistake could be the userId. I took the senderId. The receiverId encounters an authorization error with errorCode 1 and the message "An unknown error occurred". I'm not sure which one is correct.<
UPDATE 2
The receiverId seems to be correct. The second request works with it. But still not the first: 500 internal server error...
Suddenly, it works now. Maybe they changed anything in the backend.

RabbitMQ Publish to Exchange Confirmation

I would like to return a retrieve a confirmation that the message was successfully published to the exchange before closing the AMQP connection. At the moment, I am using a timeout function to allow for the message to be published before closing the connection. This is not the right way. Can someone please help to retrieve a confirmation so I can close the connection based on a successful publish?
The code I am using is below:
function toExchange(msg)
{
amqp.connect('amqp://localhost:5672', function(err, conn) //local connection
{
conn.createChannel(function(err, ch)
{
var exchange = 'MessageExchange';
ch.assertExchange(exchange, 'fanout', {durable: true});
ch.publish(exchange, '', new Buffer(msg));
console.log("Sent to Exchange: %s", msg);
});
setTimeout(function() { conn.close(); }, 5000);
});
}
You can use a RabbitMQ extension called "Publisher confirms". Here is more information: https://www.rabbitmq.com/confirms.html#publisher-confirms.
You are not notified when the message is published to the exchange, but when it is published and routed to all queues: https://www.rabbitmq.com/confirms.html#when-publishes-are-confirmed
In your case using amqplib in nodeJS you can use this snippet of code: https://www.squaremobius.net/amqp.node/channel_api.html#confirmchannel
It uses the callback #waitForConfirms(function(err) {...}) that triggers when all published messages have been confirmed.

Inviting selected users to Facebook-Event (via Graph API)

with help of docs, tutorials and this forum I managed to create an event for the logged in user on his profile or page, as he chooses.
I also figured, that for inviting friends I'd have to use events.invite.
Since I don't want to invite all of the user's friends but several, I implemented a request, which as a result returns the selected friend's ids.
Those I'm using for the events.invite call. I get bool 1 as result (which means, the invitation was sent successfully) but there is no invitation to be seen in friends bookmarks or event page.
Everything besides invitation is working.
3 questions come up:
1) Does events.invite need additional permission besides 'create_event' ?
I tryed events.invite independently and couldn't get results either...
2) Is there a better way to select friends before sending invitation? I do not want app request being sent out each time an event is created.
3) If 2 is negative, how can the app request (and bookmark) be subdued or removed from friend's profile? Deleting the request via API obviously doesn't remove the message in application requests.
* in main script: [javascript]
function sendRequest() {
FB.ui({
method: 'apprequests',
message: 'Test',
title: 'event invitation for up to 20 friends',
max_recipients: 20,
},
function (response) {
if (response && response.request_ids) {
var requests = response.request_ids.join(',');
var invite_ids = new Ajax.Request('/facebook/handle_invitation.php', {
onSuccess: function(test) { alert('Done!'); },
method: 'post',
parameters: {tid: '<?php echo $target_id; ?>',
request_ids: requests,
eid:'<?php echo $event_id; ?>',
token: '<?php echo $access_token; ?>'}
});
} else {
alert('canceled');
}
});
return false;
}
* and in 'handle_invitation.php' (called from request response):
if( isset($_POST['request_ids']) && isset($_POST['uid']) ) {
$target_id = $_POST['tid'];
$event_id = $_POST['eid'];
$access_token = $_POST['token'];
$requests = explode(',',$_POST['request_ids']);
foreach($requests as $request_id) {
$request_data = $fb->api("/$request_id?$access_token");
$invite_id[] = $request_data['to']['id'];
$fb->api("/$request_id?$access_token", "DELETE");
}
//invite friends to my event
$return = $fb->api(array(
'method' => 'events.invite',
'eid' => $event_id,
'uids' => $invite_id,
'personal_message' =>"Einladung zu meinem Event"
));
}
Hope this was not too detailed. I'd appreciate any help, since after days of reading and experimenting I'm finally stuck at this point. Thx!
The graph api now allows you to invite users by user_id. See http://developers.facebook.com/docs/reference/api/event/
invited
Create
You can invite users to an event by issuing an HTTP POST to /EVENT_ID/invited/USER_ID. You can invite multiple users by issuing an HTTP POST to /EVENT_ID/invited?users=USER_ID1,USER_ID2,USER_ID3. Both of these require the create_event permission and return true if the invite is successful.
I don't think "sent event invitation" is in the GRAPH API yet. It is available in REST API but its not working as we expect.
I found some known issues and limitations with facebook events. Please see the links below from the official documentation on facebook
Limitation on number of people that could be invited to an event.
http://www.facebook.com/help/?faq=12576#!/help/?faq=202545109787461
Event members are not receiving messages I have sent.
http://www.facebook.com/help/?page=786#!/help/?faq=188295427885002