How to send ajax request to bots business webhook? - bots.business

Hello I am trying to send ajax request to bb webhook by following code.
$.ajax({ type: "POST",
url: webhookUrl,
data: { user_id: YOUR_USER_ID },
success: success,
dataType: "json"});
Now what bjs i need to execute command by webhook🤔?

Related

How to send FCM push notification to multiple devices using google apis?

I want to send push notification to multiple devices at once. Can i pass array of tokens?
Is it possible to do using google api? Please help me with this.
request(
{
method: 'POST',
uri:
'https://fcm.googleapis.com/v1/projects/projectId/messages:send',
headers: {
'content-type': 'application/json',
Authorization: `Bearer ${token}`,
'apns-priority': 'high',
content_available: true
},
body: {
message: {
token: token,
notification: {
body: 'This is an FCM notification message!',
title: 'FCM Title'
},
android: {
notification: {
sound: 'default'
}
}
}
},
json: true
},
async function(error, response, body) {
if (error) {
console.log(error);
}
console.log(body);
}
);
If you want to make the POST requests by yourself, you can prefer to:
1) Use the legacy HTTP server protocol. With that you will be able to use the "registration_ids" field which expects an array of token strings in POST body. Docs here.
2) Stick to HTTP v1 API that you're using right now, but since "token" field is expecting only string, you can first subscribe your users to a specific topic and use that topic in "topic" field in POST body.
Additionally, you may prefer to use Admin SDK to send batch notifications. You can check for further here.

401 unauthorized Authentication parameters missing in dialogflow api

I have developed chatbots using Dialogflow api v1. There had been no change in the code. But, now the response from the server is "code":401,"errorType":"unauthorized","errorDetails":"Authentication parameters missing. I checked in Postman using the below url.
https://api.dialogflow.com/v1/query?v=519794&lang=en&query=hi&sessionId=519794&Content-Type=application/json and gave my client access token in bearer token. When I tried with post method I got error.But, when i used GET method it worked in postman. So, I tried the same code in my javascript code and got 401 unauthorized error. What's wrong here?
I have resolved this issue using the following code.
Used GET method instead of POST in Ajax call and removed JSON.stringify in the data parameter.
var text = "hello";
var iRandom = Math.floor((Math.random() * 10000000) + 1);
$.ajax({
type: "GET",
url: "https://api.api.ai/v1/query?v=324233",
contentType: "application/json; charset=utf-8",
dataType: "json",
headers: {
"Authorization": "Bearer "+accessToken
},
data: { query: text, lang: "en", sessionId: iRandom},
success: function(data) {
//desired action
},
error: function() {
console.log("Internal Server Error");
}
});
Another alternate solution:
I retained the earlier version.
var iRandom = Math.floor((Math.random() * 10000000) + 1);
type: POST,
data: JSON.stringify({ query: text, lang: "en", sessionId: iRandom}),
Instead of passing the iRandom as number, I passed it as String and I was able to get response from the dialogflow.

Script from https://account-d.docusign.com/error?aspxerrorpath=/oauth/token was blocked due to mime type mismatch

I am trying to obtain the Access Token by passing authcode by calling rest api but my response was blocked saying mime type mismatch. PFB sample code
$.ajax({
async: true, // Async by default is set to “true” load the script asynchronously
dataType: 'jsonp',
crossDomain: true,
redirect_uri: 'https://hclo365.sharepoint.com/sites/wf13test',
data: 'grant_type=authorization_code&code=eyJ0eXAiOiJNVCIsImFsZyI6IlJTMjU2Iiwia2lkIjoiNjgxODVmZjEtNGU1MS00Y2U5LWFmMWMtNjg5ODEyMjAzMzE3In0%2EAQkAAAABAAYABwCAGYGDcLfWSAgAgKUHy3C31kgCAONnoYIaQgFOsTImy5_ryv0VAAEAAAAYAAEAAAAdAAAADQAkAAAAMzRkYTY1NDktMTdjMC00MTM3LWE3YWEtYWJkYWMzNjQ0YWMzNwCWbGY1cO_JQKSrZRKWhxjbMACAZ4tNZ7fWSA%2Eaz__M8ULm--8DgmUspzcA1wa7soxB0jQgnKhIwKhRT4jDsmsmIa755xPK7sD1vKmeMM4LDISN1XignVCii1IecpEWO6PWR8gq6UToJG6DnKcPurKWXEwZblsyxf2kOXR1RtDQoev5_VxkqLKTT9rHCFB01eZzTir8SVMs5BPOWdCCufMok-lVyJoq5VRL2YoPB3iOhz8MZAVlElx0srIJJWUuHiXRImmU13__3qtRf82Kxattt_6cN8IcW9rjZDYB0dfcqIKon_Q27Fp8KYU4LEpYHVunKEli60dzWliTFX34KRGJYVpYqK-Zd6OyHuqculMPE6mctVlQbcG1DD3gQ',
url: "https://account-d.docusign.com/oauth/token", // URL to fetch data from sharepoint list
method: "POST", //Specifies the operation to fetch the list item
headers: {
Authorization : "Basic MzRkYTY1NDktMTdjMC00MTM3LWE3YWEtYWJkYWMzNjQ0YWMzOjgzNmQxNmZiLWU1MDctNDM2Ny04Y2ZlLTFiODkzOGU2MTE5Yw==",
"Access-Control-Allow-Origin": '*',
"Access-Control-Allow-Headers": 'application/json',
"accept": "application/json;odata=verbose", //It defines the Data format
"content-type": "application/x-www-form-urlencoded" //It defines the content type as JSON
},
success: function(data) {
console.log('works');
},
error: function(error) {
console.log(JSON.stringify(error));
}
})
Looking for the possible solution for this to capture the access token.
I do not think you can call DS API from AJAX calls, you will be getting CORS issue. DS Dev Blog1, DS Dev Blog2 and DS Dev Blog3 explain how you can achieve Single Page Applications with DocuSign.

webhook not working in API.ai

I have the following custom javascript code for API.AI. I have implemented a simple webhook in php to receive data on certain action. Whenever I check in API.AI console it is working fine. But with the following code it gives Webhook call failed. Error: Webhooks can be used with version '20150415' or greater. error. Please help.
$.ajax({
type: "POST",
url: baseUrl + "query",
contentType: "application/json; charset=utf-8",
dataType: "json",
headers: {
"Authorization": "Bearer " + accessToken
},
data: JSON.stringify({query: text, lang: "en", sessionId: "<?php echo uniqid();?>", v:"20170712"}),
success: function(data,url) {
console.log(url);
prepareResponse(data);
},
error: function(text) {
console.log(text);
respond(messageInternalError);
}
});
As qnguyen mention in a comment you must have ?v=20150910 in your url. For example: https://api.dialogflow.com/v1/query?v=20150910
See https://dialogflow.com/docs/reference/agent/query for more info

A node of type 'EndOfInput' was read from the JSON reader when trying to read the start of an entry. A 'StartObject' node was expected

I am trying to add a user to sharepoint group with following code
serviceUrl= Appweb + "/_api/SP.AppContextSite(#target)/web/sitegroups("+GroupId+")/users?#target='host web'";
$.ajax({
url: serviceUrl,
type: "POST",
contentType: "application/json; charset=utf-8",
dataType: 'json',
body: "{'__metadata': { 'type': 'SP.User' },'LoginName':'i:0#.f|membership|'+email }",
headers: {"accept":"application/json;odata=verbose",
"content-type": "application/json;odata=verbose",
"X-RequestDigest":$("#__REQUESTDIGEST").val()
},
async: false,
success: function (data) {
alert('success');
},
error: function (data) {
alert('fail');
}
});
The request goes to error function. Response of the request is Microsoft.SharePoint.Client.InvalidClientQueryException and the message is
A node of type 'EndOfInput' was read from the JSON reader when trying to read the start of an entry. A 'StartObject' node was expected

Resources