Calendar API Event Attendees Response Status always changes to "Needs Action" - google-calendar-api

I am doing callout from salesforce to google calendar api to upsert a google event. when i make the request, it always changes the attendee status to "NeedsAction", so when I sent request to google, attendee status was "Accepted" but in response i got "NeedsAction". Why google always changes the attendee response. Please help if anyone knows. Thanks
Request Body :
{
"kind" : "calendar#event",
"summary" : "nice 13 val",
"description" : "this is new",
"location" : "3 value friday",
"start" : {
"dateTime" : "2020-08-13T12:30:00+05:00"
},
"end" : {
"dateTime" : "2020-08-13T13:30:00+05:00"
},
"attendees" : [ {
"email" : "mohit.kumar#test.in",
"organizer" : true,
"responseStatus" : "accepted"
}, {
"email" : "test#gmail.com",
"responseStatus" : "accepted"
} ]
}
Callout :
Http http = new Http();
HttpRequest httpReq = new HttpRequest();
httpReq.setEndpoint('https://www.googleapis.com/calendar/v3/calendars/mohit.kumar#test.in/events/'+objEvent.Google_Event_Id__c);
httpReq.setTimeout(30000);
httpReq.setHeader('Content-Type', 'application/json');
httpReq.setMethod('POST');
httpReq.setHeader('X-HTTP-Method-Override','PATCH');
httpReq.setHeader('Authorization', 'Bearer ' + accessToken);
String reqBody = createEventBody(objEvent, googleSettingInfo);
if (String.isNotBlank(reqBody)) {
httpReq.setBody(reqBody);
}
if (httpReq.getBody() != null && httpReq.getBody() != '') {
HttpResponse httpRes = http.send(httpReq);
System.debug('code: ' + httpRes.getStatusCode());
if (httpRes.getStatusCode() == 200) {
System.debug('response: ' + httpRes);
System.debug('create event response body: ' + httpRes.getBody());
}
}
getting attendees response always as "needs Action" while this should be "accepted" for "test#gmail.com"
{
"created": "2020-08-11T18:51:41.000Z",
"updated": "2020-08-28T06:48:49.972Z",
"summary": "nice 13 val",
"description": "this is new",
"location": "3 value friday",
"creator": {
"email": "mohit.kumar#test.in",
"self": true
},
"organizer": {
"email": "mohit.kumar#test.in",
"self": true
},
"start": {
"dateTime": "2020-08-13T14:00:00+05:30"
},
"end": {
"dateTime": "2020-08-13T15:00:00+05:30"
},
"sequence": 16,
"attendees": [
{
"email": "test#gmail.com",
"responseStatus": "needsAction"
},
{
"email": "mohit.kumar#test.in",
"organizer": true,
"self": true,
"responseStatus": "accepted"
}
],

Proposed modification:
What about modifying the createEventBody function in order to create a simple JSON object that will only contain the attendees information with the updated statuses.
This will leverage correctly the PATCH semantics and helps a lot on improving readability.
I tested it myself and your generated JSON object returns an error on the start property. Removing that will help you solve that error too. Finally I tested that passing the attendees property to the PATCH method will work as intended.
You can try using the "Try this API" functionality before actually update your code.
Reference:
Events patch

Related

How to make a post request with a custom token document ref with firebase firestore Rest API

Here is my code below, I'm trying to send a post request using Firebase Firestore Rest API. It works, but it generates a random ref id token that links it to the post data (fields) I sent, which makes it difficult to relate to.
I want to be able to link my post data with a custom id token.
final String customIdToken9 = 'customIdToken9'
String url = "https://firestore.googleapis.com/v1/projects/myAppId/databases/(default)/documents/customers/$customIdToken9"
const _body = {
"fields": {
"androidNotificationToken": {
"nullValue": null
},
"fullname": {
"stringValue": "Custom"
},
"uid": {
"stringValue": "$customIdToken9"
},
"admin": {
"stringValue": ""
},
"email": {
"stringValue": "customer1#gmail.com"
},
"photo": {
"stringValue": ""
},
"coverPhoto": {
"stringValue": ""
},
"bio": {
"stringValue": ""
},
"role": {
"stringValue": "user"
},
"mobile": {
"stringValue": "092222"
}
}
}
http.post(url, body = _body);
When I run this code above it returns
{
"error": {
"code": 400,
"message": "Document parent name \"projects/MyAppId/databases/(default)/documents/customers\" lacks \"/\" at index 59.",
"status": "INVALID_ARGUMENT"
}
}
If I remove the customTokenId9, it works, but it generates a random token Id, which I don't want
String url = "https://firestore.googleapis.com/v1/projects/myAppId/databases/(default)/documents/customers/"
http.post(url, body = _body);
If you want to specify your own document name, you need to add a query paramater called documentId to your URL request. Here's how it should look like on your code:
final String customIdToken9 = 'customIdToken9'
String url = "https://firestore.googleapis.com/v1/projects/myAppId/databases/(default)/documents/customers?documentId=$customIdToken9"
const _body = {
"fields": {
"androidNotificationToken": {
"nullValue": null
},
"fullname": {
"stringValue": "Custom"
},
"uid": {
"stringValue": "$customIdToken9"
},
...
}
}
The client-assigned document ID to use for creating a document. It is optional. If not specified, a random ID will automatically be assigned by the service.
Full description is stated in this link and you'll see it in the Query Parameters section. You can also try to test out the API and expand it to see its curl equivalent.
Additionally, you can look up to this documentation to understand how a query parameter works. It applies on any REST API's offered by Firebase.
Why is your variable final String customIdToken but you are using $customIdToken9 it should be $customIdToken.

Sending a request to /adCreativesV2 entity doesn't return all the fields

We are in the process of designing a custom build report for our client and have recently stumbled upon a behavior which we could not puzzle. Basically, we are not getting returned the following fields
ad_creative_name
ad_creative_text
ad_creative_title
when sending a GET request as follows:
https://api.linkedin.com/v2/adCreativesV2/136236994?projection=(*,reference~(*))
We're getting a 200 OK response as per below:
"variables": {
"data": {
"com.linkedin.ads.SponsoredInMailCreativeVariables": {
"content": "urn:li:adInMailContent:5139314"
}
}
},
"test": false,
"servingStatuses": [
"RUNNABLE"
],
"type": "SPONSORED_INMAILS",
"version": {
"versionTag": "6"
},
"reference": "urn:li:adInMailContent:5139314",
"changeAuditStamps": {
"lastModified": {
"time": 1624098658000
},
"created": {
"time": 1624035613000
}
},
"review": {
"reviewStatus": "APPROVED"
},
"campaign": "urn:li:sponsoredCampaign:179783044",
"reference!": {
"message": "Unsupported URN domain: li:adInMailContent",
"status": 501
},
"id": 136236994,
"status": "ACTIVE"
}
From the response, you may also notice that we are also getting this warning
"message": "Unsupported URN domain: li:adInMailContent",
"status": 501
We've tried different API requests variations, including specifying different creatives that are active, but to no avail. Also, we were not able to find any info regarding the error above, so we are uncertain what might be causing it.
Thanks!

How can i save the fulfillmentText in dialogflow to firebase?

I am new in Learning Dialogflow, What i am trying is to save the conversation of user and the bot.
i can already save the user response to the bot but i also want to save the bot response to the firebase.
my code is like this
function HandleSaveToDB(agent){
return admin.database().ref('data').push({
bot_response: request.body.queryResult.queryText,
user_response: request.body.fulfillmentText
});
}
the bot_response is saving but the user_response is not saving.
here is the response of the JSON
{
"responseId": "50359194-cadb-44a4-b649-ebd8e4606fea-425db6e2",
"queryResult": {
"queryText": "Hi i am paul i need help",
"parameters": {
"given-name": "Paul",
"text": ""
},
"allRequiredParamsPresent": true,
"fulfillmentText": "Hi Paul how can i help you today?",
"fulfillmentMessages": [
{
"text": {
"text": [
"Hi Paul how can i help you today?"
]
}
}
],
"intent": {
"name": "projects/chatsimulator-rttunh/agent/intents/dbc7dbf8-ca8d-4f7a-86b5-a0e6eab7e0b5",
"displayName": "Greetings"
},
"intentDetectionConfidence": 1,
"diagnosticInfo": {
"webhook_latency_ms": 4992
},
"languageCode": "en"
},
"webhookStatus": {
"code": 4,
"message": "Webhook call failed. Error: DEADLINE_EXCEEDED."
}
}
I'm presuming you're talking about a Fulfillment function being hit here.
The fulfillmentText is actually located in request.queryResult.fulfillmentText, despite what you see as the output from the diagnostic info.
Please see the spec for the fulfillment request and the queryResult property of that request.

Responding to slack view_submission event with error object

I use ASP.NET Core 2.1 to build integration with Slack
Here is my modal in json format.
{
"type": "modal",
"callback_id": "send_sms",
"title": {
"type": "plain_text",
"text": "Send SMS",
"emoji": false
},
"submit": {
"type": "plain_text",
"text": "Submit"
},
"close": {
"type": "plain_text",
"text": "Cancel"
},
"blocks": [
{
"type": "divider"
},
{
"type": "input",
"block_id": "phone_number",
"label": {
"type": "plain_text",
"text": "Enter phone number",
"emoji": false
},
"element": {
"type": "plain_text_input",
"placeholder": {
"type": "plain_text",
"text": "Phone number",
"emoji": false
},
"action_id": "action_phone_number"
}
},
{
"type": "input",
"block_id": "message",
"label": {
"type": "plain_text",
"text": "Enter message",
"emoji": false
},
"element": {
"placeholder": {
"type": "plain_text",
"text": "Message",
"emoji": false
},
"action_id": "message",
"type": "plain_text_input",
"multiline": true
}
}
]
}
So when user submit form, my .net core application recieves an view_submission event and if phone number has invalid format I want to response to this event with error.
Slack docs says that I should response with such json object:
`{
"response_action": "errors",
"errors": {
"phone_number": "Invalid phone number format"
}
}`
During debugging I found out that my app actually DO load json from file and DO respond with a string that contains this json. But a still get this error on my modal
enter image description here
controller method returns Task> object but I'm not sure that it's correct
So my question is:
Does anybody know how I should response to this slack event using .net core?
As far as I understand even if I have validation error in my .net core app and I want to return error object to slack, I should respond with status 200 OK
Finnaly this question is resolved by returning
Content('json_string', "application/json");

Dialogflow response with output context crashes PHP/Symfony server

TL;DR
My PHP/Symfony server crashes when Dialogflow sends a response with output context, but works fine when the response does not have any output context.
Why is that so and how can I prevent my server from crashing ?
Some context
I'm working on a old project made by a colleague who left the company a few months ago.
The project uses Dialogflow and a PHP/Symfony server to create a chatbot.
Back in January, the project worked well, but when I tried to test it last week, I discovered our server had been irremediably removed from the host.
I reuploaded and reinstalled the server code but I cannot be 100% sure that the backup code was exactly the same as the hosted code.
Correct behaviour
I send "hey" to the server
The server transmits the message to Dialogflow
Dialogflow determines that the intent is "Welcome"
Dialogflow sends back "Salutations" to the server
I get the response "Salutations"
Faulty behaviour
I send "help" to the server
The server transmits the message to Dialogflow
Dialogflow determines that the intent is "Help"
Dialogflow sends back "[some long text]" to the server
The server crashes and returns a generic error 500
Same goes for the default fallback intent, if I send a request like "blah blah blah".
The difference
The Welcome intent does not provide output context, nor does it reset the context.
The Help intent does provide output context.
The Fallback intent does not provide output context, but does reset the context.
I verified, if I provide output context with the Welcome intent, the server crashes, and if I remove the output context from the Help intent, everything works fine.
The questions
What is going on with this project ? Why is the output context crashing my server ? How can I fix it ?
I can't just remove the output contexts from the intents, of course.
The code
<?php
namespace AppBundle\Controller;
use Ramsey\Uuid\Uuid;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Google\Cloud\Dialogflow\V2\SessionsClient;
use Google\Cloud\Dialogflow\V2\TextInput;
use Google\Cloud\Dialogflow\V2\QueryInput;
class DefaultController extends Controller
{
/**
* #Route("/messenger", name="homepage")
*
*/
public function indexAction(Request $request)
{
return $this->render('#App/messenger.twig', array());
}
/**
* #param Request $request
*
* #Route("/messenger/call/{intent}", options={"expose"=true}, name="call_assistant")
* #throws \Google\ApiCore\ValidationException
* #throws \Google\ApiCore\ApiException
* #throws \Exception
*/
public function callAssistantAction(Request $request, $intent) {
$sessionDialogFlow = $this->get('session')->get('dialogFlow_session');
if ($sessionDialogFlow === null) {
$sessionDialogFlow = Uuid::uuid4()->toString();
$this->get('session')->set('dialogFlow_session', $sessionDialogFlow);
}
$sessionClient = new SessionsClient(array(
'credentials' => realpath($this->getParameter('kernel.root_dir'). "/../web/authentDialogFlow.json")
));
$session = $sessionClient->sessionName("<my session name>", $sessionDialogFlow);
$textInput = new TextInput();
$textInput->setText($intent);
$textInput->setLanguageCode('fr-FR');
$queryInput = new QueryInput();
$queryInput->setText($textInput);
$response = $sessionClient->detectIntent($session, $queryInput); // <- this line is where the crash happens
$queryResult = $response->getQueryResult();
$fulfillmentText = $queryResult->getFulfillmentText();
return new JsonResponse(array("response" => $fulfillmentText));
}
}
The Welcome dialogflow output
{
"queryText": "hey",
"action": "input.welcome",
"parameters": {},
"fulfillmentText": "Salutations !",
"fulfillmentMessages": [
{
"text": {
"text": [
"Salutations !"
]
},
"lang": "fr"
}
],
"intent": {
"id": "<id>",
"displayName": "Default Welcome Intent",
"priority": 500000,
"events": [
"WELCOME"
],
"action": "input.welcome",
"messages": [
{
"text": {
"text": [
"Hi! How are you doing?",
"Hello! How can I help you?",
"Good day! What can I do for you today?",
"Greetings! How can I assist?"
]
},
"lang": "en"
},
{
"text": {
"text": [
"Salut !",
"Bonjour !",
"Salutations !",
"Bienvenue !"
]
},
"lang": "fr"
}
]
},
"intentDetectionConfidence": 1,
"languageCode": "fr",
"slotfillingMetadata": {
"allRequiredParamsPresent": true
},
"id": "<id>",
"sessionId": "<id>",
"timestamp": "2019-07-15T07:41:28.778Z",
"source": "agent",
"webhookStatus": {
"webhookEnabledForAgent": true
},
"agentEnvironmentId": {
"agentId": "<id>",
"cloudProjectId": "<id>"
}
}
The Help dialogflow output
{
"queryText": "aide",
"parameters": {},
"fulfillmentText": "<long text>",
"fulfillmentMessages": [
{
"text": {
"text": [
"<long text>"
]
},
"lang": "fr"
}
],
"intent": {
"id": "<id>",
"displayName": "Help",
"priority": 500000,
"messages": [
{
"text": {
"text": [
"<long text>"
]
},
"lang": "fr"
}
]
},
"intentDetectionConfidence": 1,
"languageCode": "fr",
"slotfillingMetadata": {
"allRequiredParamsPresent": true
},
"id": "<id>",
"sessionId": "<id>",
"timestamp": "2019-07-15T13:05:25.255Z",
"source": "agent",
"webhookStatus": {
"webhookEnabledForAgent": true
},
"agentEnvironmentId": {
"agentId": "<id>",
"cloudProjectId": "<id>"
}
}
Feel free to ask for additional information.
After days of gloom, it turned out my server was missing PHP extension bcmath needed by google/protobuf. I enabled it in my php.ini and everything worked fine.
You can find a bit more information on the Github issue : https://github.com/googleapis/google-cloud-php/issues/2120

Resources