dialogflow api does not request my webhook - dialogflow-es

I want to request my dialogflow agent through its api.
Here is my code:
const request = require('request');
const _ = require('underscore');
const apiBase = 'https://api.dialogflow.com/v1/query/';
const token = ...;
let options = {
'url': apiBase,
'headers': {
'Authorization': 'Bearer ' + token
},
'json': {
'v': '20150910',
'lang': 'fr',
'sessionId': 'abcdefgh'
},
}
let query = 'welcome_intent';
options.json.query = query;
request.post(options , (e, r, b) => {
console.log('result: ', b.result)
});
The string 'welcome_intent' has been added to the user says of the welcomeIntent. I get the following result:
result:
{ source: 'agent',
resolvedQuery: 'welcome_intent',
speech: '',
action: 'intent.welcome',
parameters: {},
metadata:
{ inputContexts: [],
outputContexts: [],
intentName: 'welcomeIntent',
intentId: '104a6251-fa1a-404a-a042-dfa1ce9118a8',
webhookUsed: 'true',
webhookForSlotFillingUsed: 'false',
contexts: [Array] },
score: 1 },
It triggers the correct intent which should use the webhook to fulfill the answer. But it does not actually request my webhook. It is said in this doc that I should have a field fulfilment in my result json. I don't have this field.
Am I doing something wrong ? I can make a subsequent call to my webhook using the DF result, but can I avoid it ?
thanks

Related

MailChimp: set Language with nodejs SDK

I'm trying to set a suscriber's Language with MailChimp nodejs SDK while adding him/her to a list.
The nodejs SDK calls the API https://us2.api.mailchimp.com/3.0/lists/<list-ID>/members, and it successfully creates a new member. However, it doesn't set the user's language. I read online that I have to pass the Accept-Language header with my HTTP request, so it is what I did.
In order to be able to add a custom header using the SDK, I slightly edited the SDK to add a defaultHeaders option. With this modification, the header is correctly set, but unfortunately it doesn't change anything: the new member still doesn't have the language set.
Here is my code:
import mailchimp from "#mailchimp/mailchimp_marketing";
export const handler = async(event) => {
const params = JSON.parse(event.body);
mailchimp.setConfig({
apiKey: process.env.apiKey,
server: process.env.server,
defaultHeaders: {
'Accept-Language': event.headers['accept-language'],
},
});
const email = params.email;
const firstname = params.name.substring(0, params.name.indexOf(' ')) || "";
const lastname = params.name.substring(params.name.indexOf(' ') + 1) || "";
return await mailchimp.lists.addListMember(process.env.listId,
{
email_address: email,
status: 'subscribed',
email_type: 'html',
merge_fields: {
FNAME: firstname,
LNAME: lastname,
},
}
);
};
The generated request is the following:
Request {
method: 'POST',
url: 'https://us2.api.mailchimp.com/3.0/lists/<list-ID>/members',
header: {
'User-Agent': 'node-superagent/3.8.1',
Authorization: 'Basic XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX=',
'Accept-Language': 'fr-FR,fr;q=0.9,en-US;q=0.8,en;q=0.7',
'Content-Type': 'application/json',
Accept: 'application/json'
},
writable: true,
cookies: '',
qs: {},
qsRaw: [],
data: {
email_address: '<the-tested-email-address>',
status: 'subscribed',
email_type: 'html',
merge_fields: { FNAME: 'Firstname', LNAME: 'Lastname' }
},
}
Still, the created member doesn't have the language set.
Please help me, it would really be appreciated 🙏
How can I set a new member's language when creating it using MailChimp API?

How can i send calendar invitaion and make sure it sit in gmail and outlook calendar using mailgun(node js)?

I am using mailgun(node js) to send an calendar invite, I am able to send invites but it is not adding to calendar automatically.
How we can automate this calendar invite to gmail, outlook calendar?
How can i achieve Yes, Maybe, No or RSVP or accept or reject options for both gmail and outlook using mailgun(node js) using ical-generator, Ex: var ical = require('ical-generator');?
gmail image
outlook image
Hi Robert,
Thanks for the your time and suggestion.
I have tried using the similar .ics file which gamil gives but it really didn't work to auto sync to calendar or "Yes", "No", "May be" options.
Here is the other example what i have written and trying auto calendar sync and "Yes", "MayBe", "No"options.
Using node module 'ical-generator'.
var ical = require('ical-generator');
var eventObj = {
'start' : '2022-06-02T06:59:52.653Z',
'end' : '2022-06-02T07:59:52.653Z',
'title': "Test mail",
'subject': 'Hey There, Im testing API',
'description': 'Hi User',
"Content-Type": "text/calendar,method=REQUEST",
"method": "REQUEST",
'url': "<domain>",
'id' : '125756xr378',
'organiser' : {'name' : 'Narendra M', 'email':'narendrahd#example.in'},
'location' : 'USA, main',
organizer: { name: 'Narendra M', email: 'narendrahd#example.in' },
attendees: [
{ name: 'Narendra M', email: 'narendrahd#example.in', rsvp: true, partstat: 'ACCEPTED', role: 'REQ-PARTICIPANT' },
],
};
var cal = ical();
Creation of an event using ical.
cal.createEvent({
start: eventObj.start,
end: eventObj.end,
summary: eventObj.title,
method: eventObj.method,
uid: eventObj.id, // Some unique identifier
sequence: 0,
subject: eventObj.subject,
description: eventObj.description,
'Content-Type': "text/calendar,method=REQUEST",
location: eventObj.location,
organizer: {
name: eventObj.organiser.name,
email: eventObj.organiser.email
},
attendees: [
{ name: 'Narendra M', email: 'narendrahd#example.in', rsvp: true, partstat: 'ACCEPTED', role: 'REQ-PARTICIPANT' },
],
});
var path = __dirname + eventObj.id + '.ics';
cal.saveSync(path);
craetion of request and rest call to run mailgun API
var request = require('request');
var fs = require('fs');
var options = {
'method': 'POST',
'url': 'https://api.mailgun.net/v3/<domain>/messages',
'headers': {
'Authorization': 'Basic <token>'
},
formData: {
'from': 'noreply#dummy.in',
'to': ['narendrahd#example.in', 'iamnotveda#example.com'],
'subject': 'Hey There, Im testing API',
'text': 'Hi User',
// 'html': '\'<html><body><p>Hi User,</p></body></html>\'',
'attachment': [{
//'value': fs.createReadStream('/Users/invite.ics'),
'value': fs.createReadStream(path),
'options': {
'filename': 'invite.ics',
'contentType': "application/ics,method=REQUEST"
}
},
]
}
};
request(options, function (error, response) {
if (error) throw new Error(error);
console.log(response.body);
});
Thanks in advance.
Narendra
I suspect partstat: 'ACCEPTED' for attendee could be a culprit here, consider changing it to 'NEEDS-ACTION'.
I recommend checking out this answer which doesn't use ical-generator. Export the raw iCal file and compare the output.

PayPal Partner Referrals API URL

I am having trouble setting up Partner Referrals when calling the PayPal API using Node.
Every time I attempt to call the API I receive the following error:
error: "invalid_token"
error_description: "The token passed in was not found in the system"
According to the documentation the URL to call is https://api-m.sandbox.paypal.com/v2/customer/partner-referrals
Looking at the URL and the error message, I believe I am getting this error because I am using production credentials, not sandbox. However, I cannot find any documentation showing the production URL for this.
Am I correct in believing this is the sandbox URL? What is the production URL if so?
Ive followed the onboarding checklist but cant seem to make this work.
Here is my code:
getAuthToken = async () => {
const clientIdAndSecret = "mylongsecret";
const authUrl = "https://api-m.paypal.com/v1/oauth2/token";
const base64 = Buffer.from(clientIdAndSecret).toString('base64')
const response = await fetch(authUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Accept-Language': 'en_US',
'Authorization': `Basic ${base64}`,
},
body: 'grant_type=client_credentials'
});
const data = await response.json();
return data;
}
setUpMerchant = async () => {
let authData = await this.getAuthToken();
const partnerUrl = "https://api-m.sandbox.paypal.com/v2/customer/partner-referrals";
let data = {
"operations": [
{
"operation": "API_INTEGRATION",
"api_integration_preference": {
"rest_api_integration": {
"integration_method": "PAYPAL",
"integration_type": "THIRD_PARTY",
"third_party_details": {
"features": [
"PAYMENT",
"REFUND"
]
}
}
}
}
],
"products": [
"EXPRESS_CHECKOUT"
],
"legal_consents": [
{
"type": "SHARE_DATA_CONSENT",
"granted": true
}
]
};
const request = await fetch(partnerUrl, {
method: 'POST',
headers: {
'Authorization': 'Bearer '+authData.access_token,
'Content-Type': 'application/json',
'data': data,
},
});
const partnerData = await request.json();
return partnerData;
}
Edit: I discovered the issue was I was running a GET request instead of a POST. The accepted answer is the correct URL
According to the documentation the URL to call is https://api-m.sandbox.paypal.com/v2/customer/partner-referrals
The production URL does not have sandbox. in the domain.

How to query an account to get only single object in quickbooks?

I am calling this function to get the accounts details with particular Name
const getAccount = async ({ realmId, auth }) => {
const postBody = {
url: `https://sandbox-quickbooks.api.intuit.com/v3/company/${realmId}/query?query=select * from Account where Name='Sales of Product Income'`,
headers: {
Accept: "application/json",
"Content-Type": "application/x-www-form-urlencoded",
Authorization: "Bearer " + auth
}
};
const data = await rp.get(postBody);
return JSON.parse(data);
};
However it is giving me data in an array
{
Account: [
{
Name: 'Sales of Product Income',
SubAccount: false,
FullyQualifiedName: 'Sales of Product Income',
Active: true,
Classification: 'Revenue',
AccountType: 'Income',
AccountSubType: 'SalesOfProductIncome',
CurrentBalance: 0,
CurrentBalanceWithSubAccounts: 0,
CurrencyRef: [Object],
domain: 'QBO',
sparse: false,
Id: '79',
SyncToken: '0',
MetaData: [Object]
}
],
startPosition: 1,
maxResults: 1
}
So I need to know is there any api to get single object instead of array in quickbooks or can I pass some parameter to get object?
This question is quite specific for quickbooks api. I never use this API before, but following the document, they provide filter data query like SQL
So, I think you can use a same api and change query. Something like SELECT * FROM your_table WHERE id = your_book_id

SHA1 signature invalid when using an array in POST parameters

I am using an exchange API to create a bot. The exchange uses SHA1 and a private key to sign HTTP requests. Everything is working except when one of my POST parameters is an array.
I tried using JSON.stringify and querystring.stringify instead of just having the array as is. I even tried sending the parameters as a string, but the API response says it has to be an array.
let api_key = 'api_key';
let secret = fs.readFileSync('./key.pem').toString('ascii');
var params: any = {
amount: '1',
api_key,
begin_time: '',
end_time: '',
market: 'USDT',
market_type: '1',
page: '1',
price: '150',
size: '10',
token: 'LTC',
tokens: 'LTC', //this must be an array, but when I make it an array the signature becomes invalid
type: '2',
};
const hash = crypto.createSign('sha1');
hash.update(JSON.stringify(params));
const signature = encodeURIComponent(hash.sign(secret, 'base64'));
params = {
sign: signature,
...params,
};
console.log(params);
var api_endpoint = '/api_market/getBalance';
var url = 'https://api.bcex.vip' + api_endpoint;
var http_header = {
'Content-Type': 'application/x-www-form-urlencoded',
};
request.post(
url,
{
headers: http_header,
body: querystring.stringify(params),
},
function(error, response, body) {
if (error) {
// res.json(error);
console.error(error);
} else {
// res.json(body);
// console.log(response);
console.log(JSON.parse(body));
}
},
);
}
API Wiki:
https://github.com/BCEX-TECHNOLOGY-LIMITED/API_Docs/wiki/Interface
Signature Instructions
https://github.com/BCEX-TECHNOLOGY-LIMITED/API_Docs/wiki/Sign
The endpoint point getBalance needs tokens to be an array
It turns out that the problem is with querystring library, I changed it to qs and now it works.

Resources