Unable to send message to end user (msteams) via Bot - json

Facing issue to send proactive message to the end user (msteams), via bot service,
I try using the bot framework python SDK, where I am getting the following error even for getting conversation id.
botbuilder.schema._models_py3.ErrorResponseException: Operation returned an invalid status code 'Unauthorized'
Hence I try to simulate calls via postman and rest API's, in here I am able to get conversation id successfully, but if I try to use that conversation id to further send a message via activities I am not able to do it. following is rest endpoint and payload. In here I am getting an error of incorrect payload.
https://smba.trafficmanager.net/apis/v3/conversations/8:orgid:949a3f72-b82c-4b89-b2de-9defbe6ae7cd/activities
{
"type": "message",
"recipient": {
"id": "29:1ZcsKdk0rsLmsywvI2SNQ2J7OIz"
},
"from": "bot",
"channelData": {
"notification": {
"alert": "true"
}
},
"text": "Hello world"
}

There was an issue with payload, I added BOT_ID along with name and able to successfully post message to end user. Following is working payload.
Payload:
{ "type":"message",
"recipient":{
"id":"29:1dUxQXVlH6QGByu1T9MR4p5g0c5URMaBtKqGU74C3zdowO78nPbuu2dg- qj9o02OkJ4MYXt2I-nxDgf9ga9EY5w"
},
"from":{
"id":"28:d7afe8c9-f0cd-434f-8906-be2b744229ac",
"name":"bot"
},
"channelData":{
"notification":{
"alert":"true"
}
},
"text":"Hello "
}

Related

Where to view watson assistant error logs

A webhook call fails, how do I see the detailed logs?
The testing webhooks page describes that the errors are put in output.webhook_error.<result_variable>. For example if your result variable is webhook_result_1 then the output is in output.webhook_error.webhook_result_1.
As described in the documentation, if an error happens then in the "Assistant responds" section of the dialog node editor, the "If assistant recognizes" anything_else should be used, so you can put in there The callout generated this error: <? output.webhook_error.webhook_result_1 ?>..
This will show more information. For example if I configure an API to throw an Error, I will get back:
The callout generated this error: {"response_code":400,"message":"Webhook call was not successful. Response code is [400].","response_body":{"code":"cff11d18150e8018d5e304ac3fc35c94","error":"There was an error processing your request."},"content_type":"application/json"}.
If this error happens when the Bot is being used live, then in the logs the webhook response body will be captured. If you use the Try It Out panel in the UI then the logs are not captured.
In the Assistant UI for the Skill in the Analytics tab the conversation is shown. In the "User conversations" part of the UI the text of the conversation is captured, but you will only see the webhooks error if you add output as described above.
The API can be used to fetch logs for a workspace or skill which include the webhook error details. See List Log Events in a Workspace. If you are using a Skill then you can find out the URL to use from the Assistant UI. On the Skills list page, on the particular skill click the ... menu and select View API Details. The Legacy v1 workspace URL: shows the workspace ID to use.
For example if the Legacy v1 workspace URL: is https://gateway.watsonplatform.net/assistant/api/v1/workspaces/ce13f844-c3a7-4f36-97c6-a0ac704024a6/message the URL to use to fetch logs is https://gateway.watsonplatform.net/assistant/api/v1/workspaces/ce13f844-c3a7-4f36-97c6-a0ac704024a6/logs?version=2020-04-01
In the workspace log there will be the details of the user conversation where a webhook error happened in webhook_error:
"output": {
"generic": [
{
"response_type": "text",
"text": ""
},
{
"response_type": "text",
"text": "The callout generated this error: {\"response_code\":400,\"message\":\"Webhook call was not successful. Response code is [400].\",\"response_body\":{\"code\":\"cff11d18150e8018d5e304ac3fc35c94\",\"error\":\"There was an error processing your request.\"},\"content_type\":\"application/json\"}."
},
{
"response_type": "text",
"text": "Customer email is <? context.webhook_result_1.message ?>."
}
],
"text": [
"",
"The callout generated this error: {\"response_code\":400,\"message\":\"Webhook call was not successful. Response code is [400].\",\"response_body\":{\"code\":\"cff11d18150e8018d5e304ac3fc35c94\",\"error\":\"There was an error processing your request.\"},\"content_type\":\"application/json\"}.",
"Customer email is <? context.webhook_result_1.message ?>."
],
"nodes_visited": [
"slot_2_1520179906877",
"handler_3_1520179906877",
"node_1_1520179877410",
"node_9_1530805081298",
"response_5_1604940050659",
"node_7_1520180645829"
],
"webhook_error": {
"webhook_result_1": {
"response_code": 400,
"message": "Webhook call was not successful. Response code is [400].",
"response_body": {
"code": "cff11d18150e8018d5e304ac3fc35c94",
"error": "There was an error processing your request."
},
"content_type": "application/json"
}
},
"nodes_visited_details": [

AWS API Gateway Mapping Template JSON

I've got a API stage that's NOT using "Lambda Proxy integration" which has a Lambda function passing an error.
In the mapping template I have this:
$input.path("$.errorMessage")
Which results in the output of this:
{
"headers": {
"apiVersion": "20190218.1",
"isTesting": true
},
"body": {
"statusCode": 503,
"status": "Service Unavailable",
"title": "One or more of our data providers are currently offline for scheduled maintenance"
}
}
The header values are mapped to template headers and pull through correctly, however I need the body to transform to this:
{
"statusCode": 503,
"status": "Service Unavailable",
"title": "One or more of our data providers are currently offline for scheduled maintenance"
}
Whatever I have tried, body always returns as a blank string, an empty body, or an invalid JSON.
This is the closest I've got but it returns an invalid JSON:
$util.parseJson($input.path("$.errorMessage")).body
Result (comes back with no quotes):
{statusCode=503, status=Service Unavailable, title=One or more of our data providers are currently offline for scheduled maintenance}
Is it possible to do what I'm after? I can't find a reverse for $util.parseJson (i.e, stringify).
Thanks!
I think the original poster has probably moved on in the past 11 months, but in case anyone else stumbles across this question, $input.json('$.errorMessage.body') should work.

how to Create subscription for sent items folder using Microsoft graph api

following post request give an error when creating a subscription for the Sent Items folder using Microsoft Graph
var apiUrl = "https://graph.microsoft.com/v1.0/subscriptions";
Request
{
"resource": "me/mailFolders('Sent Items')/messages",
"changeType": "created,updated,deleted",
"clientState": "320a6f10-9c62-4e59-a395-8cd27941b597",
"notificationUrl": "https://webhook.site/aaaa-6f49-4906-aaaa-e911f9391695",
"expirationDateTime": "2018-08-28T12:53:41.4830081+00:00"
}
Error Response
{
"error": {
"code": "ExtensionError",
"message": "Operation: Create; Exception: [Status Code: BadRequest; Reason: Bad Request]",
"innerError": {
"request-id": "359f51a6-5b12-41f6-8a02-a68ba4c10585",
"date": "2018-08-27T06:42:18"
}
}
}
Unfortunately the webhook.site test site that you are using does not implement the validation token protocol that is required to setup a subscription. The webhook must return the value of the validationToken query parameter in the response body for the subscription to be created correctly.
i changed the resource property value for folder name 'Sent Items' to 'SentItems' . here is the working request
{
"resource": "me/mailFolders('SentItems')/messages",
"changeType": "created,updated,deleted",
"clientState": "320a6f10-9c62-4e59-a395-8cd27941b597",
"notificationUrl": "https://webhook.site/aaaa-6f49-4906-aaaa-e911f9391695",
"expirationDateTime": "2018-08-29T12:53:41.4830081+00:00"
}

Getting 401 unauthorised when calling calendar api of office 365

I am trying to access the office 365 calendar api to create an event. The steps i followed are
Created app and registered it in azure
Gave permisissions to the app
Hitting https://login.microsoftonline.com/{{tenantid}}/oauth2/token to get the access token
body :
{
"grant_type":"client_credentials",
"client_id": "*****",
"client_secret": "****",
"resource":"https://outlook.office.com"
}
Response :
{
"token_type": "Bearer",
"expires_in": "3600",
"ext_expires_in": "262800",
"expires_on": "1532026206",
"not_before": "1532022306",
"resource": "https://outlook.office.com",
"access_token":"******"
}
When i pass this access token to https://outlook.office.com/api/v2.0/me/events which creates events. it gives me 401 unauthorised. Body of the request is as shown below. Someone please assist.
{
"Subject": "Discuss the Calendar REST API",
"Body": {
"ContentType": "HTML",
"Content": "I think it will meet our requirements!"
},
"Start": {
"DateTime": "2019-02-02T18:00:00",
"TimeZone": "Pacific Standard Time"
},
"End": {
"DateTime": "2019-02-02T19:00:00",
"TimeZone": "Pacific Standard Time"
},
"Attendees": [
{
"EmailAddress": {
"Address": "arulvelug#hexabot.onmicrosoft.com",
"Name": "Arulvelu G"
},
"Type": "Required"
}
]
}
To do authorization of office 365 and use REST API via Postman, here is a solution for your reference:
First: get security Token
Access [https://login.microsoftonline.com/extSTS.srf] via Http Post method. The content of the http request is as follows.
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope"
xmlns:a="http://www.w3.org/2005/08/addressing"
xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-
utility-1.0.xsd">
<s:Header>
<a:Action
s:mustUnderstand="1">http://schemas.xmlsoap.org/ws/2005/02/trust/RST/Issue</a:Action>
<a:ReplyTo>
<a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address>
</a:ReplyTo>
<a:To s:mustUnderstand="1">https://login.microsoftonline.com/extSTS.srf</a:To>
<o:Security s:mustUnderstand="1"
xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<o:UsernameToken>
<o:Username>[username]</o:Username>
<o:Password>[password]</o:Password>
</o:UsernameToken>
</o:Security>
</s:Header>
<s:Body>
<t:RequestSecurityToken xmlns:t="http://schemas.xmlsoap.org/ws/2005/02/trust">
<wsp:AppliesTo xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy">
<a:EndpointReference>
<a:Address>[endpoint]</a:Address>
</a:EndpointReference>
</wsp:AppliesTo>
<t:KeyType>http://schemas.xmlsoap.org/ws/2005/05/identity/NoProofKey</t:KeyType>
<t:RequestType>http://schemas.xmlsoap.org/ws/2005/02/trust/Issue</t:RequestType>
<t:TokenType>urn:oasis:names:tc:SAML:1.0:assertion</t:TokenType>
</t:RequestSecurityToken>
</s:Body>
</s:Envelope>
The demonstration screenshot in Postman:
And the response content will include a security token as below, we can use this security token to get Access Token of office 365.
Second: get Access Token
Here i show you how to get access token, I get it of my SharePoint using the security token.
Access [https://yourdomain.sharepoint.com/_forms/default.aspx?wa=wsignin1.0] via http Post method. The content of the request is the security token that we have got above as below.
And the response as below:
We can see that there are two cookie, rtFa and FedAuth in response header, and these two cookie need to be added to the request in subsequent request.
Third: get Request Digest
Access [https://yourdomain.sharepoint.com/_api/contextinfo] via http Post method with that two cookies which we have got above.
And the response as below:
This is the final Token we want!
Then we can use REST API of our app in O365, like SharePoint , we only need to add this token and the previous two cookie, as shown in the following figure.

Google Search Console 401 Bad Request issue without using Client Library

So, Here are 3 steps.
I called oAuth2 with following url:
https://accounts.google.com/o/oauth2/v2/auth
?scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fwebmasters%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fwebmasters.readonly
&client_id=___.apps.googleusercontent.com
&redirect_uri=urn:ietf:wg:oauth:2.0:oob
&response_type=code
&approval_prompt=force
&access_type=offline
I get the code, suppose: 4/QVgPaCMqp94____qBC4NY_d54IcRj7U9mJc
Then I'm making a request for access_token, by making a POST request to https://accounts.google.com/o/oauth2/token with client_id, client_secret, redirect_uri, grant_type, and I get a JSON like:
'access_token' => ya29.CjHzAgC4js6Guv-1pt_rE____q8XIxiXOXOaSZW9NLRjKCTI3izBi,
'expires_in' => 3600,
'refresh_token' => 1/dL3ENA-EVI0rEb6D-OGqw_____iFe2ZNdEq4,
Now, I am making a request with that access_token or in cases of expiry with a renewed access_token to Google Search Console, which I have added in scopes.
My request is similar to this: https://developers.google.com/webmaster-tools/v3/urlcrawlerrorssamples/list#try-it
But I get an 401 unauthorized error, with a json like following:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "required",
"message": "Login Required",
"locationType": "header",
"location": "Authorization"
}
],
"code": 401,
"message": "Login Required"
}
}
Considering I have done the process correctly, I think I have missing some parameters or providing some wrong value.
I have not used Google Client Library, instead used the REST API framework directly.
Can anybody give some clue please? Thank you.
The reason is, URL query parameter must be ?access_token= and not ?key= The later can be used only in case of direct API access and not oAuth.