I am trying to post an image to a Pinterest board via a webhook (Maker service), but every time I try I get a success response, but in IFTTT on actions, I see a Applet failed: There was a problem with the Pinterest service message. What can be wrong? The images I try to post are hosted on my own server.
function pinterest_post(image, description, boards) {
request({
url: 'https://maker.ifttt.com/trigger/pinterest_post/with/key/*******-***********-*',
method: 'POST',
json: {
"value1": boards,
"value2": image,
"value3": description
}
}, function (error, response) {
if (error) {
console.log('Error sending message: ', error);
} else if (response.body.error) {
console.log('Error: ', response.body.error);
} else {
console.log(response);
}
});
}
It's possible that you can't send images which are multiform data to pinterest webhook. I'm trying to figure out how to do this right now myself. I don't believe you can do it though, see this post: Can I post an image in json request to URL in IFTTT Maker Trigger?
Related
Good morning,
I'm having an annoying problem with some thing that's i'm trying to make using the youtube comment api , i'm trying to add automatically a comment when a video on my channel has been uploaded , it works as intended for the first 5 seconds and i get a notification that my comment was added , ,and i can see it after i uploaded my video , but after 3 - 5 seconds after , my comment gets deleted on it's own.
i looked for what could the cause of this could be , and i thought " oh maby it's considered as spam " , so i look in my uploaded video comments spam tab , and NOTHING , the comments are no where to be found.
i tried this process for around 10 times and still nothing , can someone help me out please ?
Thank you !
Here's what i do :
I subscribe to the youtube webhook to get a notification when a user uploads a new video
when i receive a notification , i send a push notification to my android app , so i can get an access_token from my android app using the google api.
once i get the token , isend it to my server so i can use it to comment on my new video.
Here is the code i use to insert a comment in the backend ( in node js ) :
function insertYoutubeComment(videoId,channel_id,message,access_token,comment){
return new Promise((resolve, reject) => {
request({
method: 'POST',
url: 'https://www.googleapis.com/youtube/v3/commentThreads',
headers: {
'User-Agent': 'Request-Promise'
},
body: {
"snippet": {
"videoId": videoId,
"channelId": channel_id,
"topLevelComment": {
"snippet": {
"textOriginal": message
}
}
}
},
qs: {
part: 'snippet',
access_token: access_token
},
json: true
}, function (error, response, body) {
console.log('body ==== ', body);
if (error) {
console.log('body', error.stack);
console.log('error in when posting comment ', error.stack);
resolve(error.stack);
// return reject(error);
}
console.log("Videos ==== ",comment.video);
let videos = comment.video
videos.push(videoId)
let bod = {}
console.log("Updating videos ");
Object.assign(bod, {
video: videos,
});
console.log("Body in update =====",body);
commentmodel.updateOne(
{ _id: comment._id },
bod,
function (err, user) {
if (err) {
console.log("Error updating ")
resolve("comment Error");
} else {
console.log("Updated user ===",user);
resolve("comment inserted");
}
}
);
//res.json({ message: "Comment inserted", status: 200, data: comment });
// return resolve(body);
});
});
}
[REGISTER SHIFT/ ASSIGNMENT FORM]
Here is my form, let me describe it; it register next week working hours, I design there are 2 cases: add new and edit in the same form.
When user select an employee, if not register shift yet, we let user register for this employee, if shift is registered already, user can edit in the same form. And I think it will be better not refresh the page, every time user change employee, the form just update and let user add/edit then submit it by post method.
I searched the web, and found a recommendation for ajax/jQuery.
Any more recommendations for me? I've just learn Nodejs/Express with PostgreSQL database.
I am trying to use ajax to load mypage from post event, I call error function in ajax to see what the error is and get:
Parsing JSON Request failed. Status 200.
I'm using NodeJS Express Server, EJS view engine, body-parser, postgresql db.
pool.connect((err, client, release) => {
if (err) {
return console.error('Error acquiring client', err.stack)
}
client.query(
'SELECT * FROM "Employee"', (err, result) => {
release()
if (err) {
res.end();
return console.error('Error executing query', err.stack);
}
console.log(typeof(result));
res.type('json');
res.render("index", {emplist : result});
res.end();
})
})
My ajax function:
$.ajax({
url: "/addshift",
type: "POST",
data: JSON.stringify(employee),
dataType: "application/json",
contentType: 'application/json',
complete: function () {
console.log("go into complete !");
},
success: function (response) {
console.log(response);
console.log("go into success !");
},
error:function(x,e) {
if (x.status==0) {
alert('You are offline!!\n Please Check Your Network.');
} else if(x.status==404) {
alert('Requested URL not found.');
} else if(x.status==500) {
alert('Internel Server Error.');
} else if(e=='parsererror') {
alert('Error.\nParsing JSON Request failed. ' + x.status);
} else if(e=='timeout'){
alert('Request Time out.');
} else {
alert('Unknow Error.\n'+x.responseText);
}
}
});
let's see:
"I am trying to use ajax to load mypage from post event"
Ok, so I suppose you want to get a fully formed HTML page from your $post.
Then, I see:
console.log(typeof(result));
res.type('json');
res.render("index", {emplist : result});
res.end();
res.render will return HTML, this is good for your goal. BUT, you're also specifying a JSON type with res.type. This is causing the error. HTML is not JSON clearly.
Furthermore, you don't need the call to res.end(). res.render() will finish the transaction correctly on its own, res.end is for errors or unexpected conditions.
Your ajax code is ok, but if you're trying to update an html component, like a select, you need to do that manually using the response from ajax, like so:
$("#selectElem").html(response);
Furthermore, you should check your result object from the SELECT * FROM EMPLOYEE query is correctly formatted as proper JSON
Currently attempting to integrate Azure Bot Framework with external platforms like Integromat. I am using the code snippet below to send the first name and mobile number submitted by the user. The user input is sent to an integromat webhook, which sends a webhook response.
bot.dialog('WebTest', function (session) {
session.send('conversation.id: ' + session.message.address.conversation.id);
session.userData.convoID = session.message.address.conversation.id;
// var request = require('request');
// var url = "https://hook.integromat.com/y6d18ahnsfanbkwqfdmygkwd2ft93vr2"
request.post({
headers: { 'content-type': 'application/x-www-form-urlencoded' },
url: 'https://hook.integromat.com/ynwbud77o7up7rrhl3m8tvdriquhtess',
body: 'first=' + session.userData.first + '&mobile=' + session.userData.mobile + '&convoID=' +session.userData.convoID
}).on('response', function (response) {
//session.send(response);
response.on('data', function (data) {
console.log('data: ' + data);
})
// session.send(data)
});
// session.send(data);
//session.send(response);
session.send("This service is still under construction");
}).triggerAction({ matches: /^webby/i })
The response is correctly logged in the console
https://i.stack.imgur.com/XQC8u.png
However, I am not sure as how I would be able to send it back to the bot and display it to the user.
I have explored the Directline API as an option, acquiring the conversation ID and following the documentation.
I used this link:
https://directline.botframework.com/v3/directline/conversations/{{1.convoID}}/activities
And sent the following request content as a json payload along with the authorization key as a header:
{
"type": "message",
"from": {
"id": "user1"
},
"text": "hello"
}
Although for this, I am getting a 404 error, with a "BadArgument" and "Unknown conversation" error.
Any help that would put me in the right direction would be appreciated, thanks!
I am not 100 percent sure what specifically you would like to do with your data within this function:
response.on('data', function (data) {
console.log('data: ' + data);
})
But the reason that session.send(data) doesn't work after this should be due to data being an object rather than a string. In this case you can do anything to make the argument a string instead, from something as simple as JSON.stringify(data) to formatting an output with the fields.
If a directline call was made from inside the bot, it likely fired off without failure because you can communicate from bot to bot via that API; but if the conversationID resolves to one within the bot currently being used (or simply does not exist yet) then an error is expected.
I am trying to follow the dialogflow tutorial. I have set up a node.js webhook, that is called from Dialogflow, inside the webhook code I call out to an api. However, my node.js webhook is saying "Error: getaddrinfo ENOTFOUND". This works fine when I run it in visual code but cannot find the api with in the nodejs webhook, when called via DialogFlow. There is something about the fact that it is being called from Dialogflow that seems to be making it not work.
I have spent a lot of time on this, and had previsouly discovered that DialogFlow wont work with https where it is a self signed certificate, as such I put an azure function, so the webhook calls the azure function and then the azure function call the api that I need.
Sorry for the long post...
Here is the node.js code:
'use strict';
const http = require('http');
var request = require('request');
const apiUrl ="https://myapi";
exports.saledurationWebhook = (req, res) => {
// Get the city and date from the request
// let city = req.body.queryResult.parameters['geo-city']; // city is a required param
let city = "sdjk";
// Call the weather API
callSalesDurationApi(city).then((output) => {
res.json({ 'fulfillmentText': output }); // Return the results of the weather API to Dialogflow
})
.catch((err) => {
console.log(err);
//res.json({ 'fulfillmentText': `I don't know the sales duration is but I hope it's quick!` });
res.json({ 'fulfillmentText': err.message});
})
;
};
function callSalesDurationApi(city) {
return new Promise((resolve, reject) => {
console.log('API Request: ' + apiUrl);
var myJSONObject = {
"Inputs": "stuff"
};
request({
url: apiUrl,
method: "POST",
json: true, // <--Very important!!!
body: myJSONObject
}, function (error, response, body) {
console.log("successfully called api");
let output = "Current conditions in the " + body;
console.log(output);
console.log(body);
resolve(output);
});
});
}
Does anyone know why this might be happening? Or what frther steps I can take to investigate it? I have already looked at the loges for the webhook, and for the azure function.
Any help would be really gratefully recieved, I have already wasted days on this. If this is a duplicate question then I am sorry, I have tried to look for existing answers on this issue.
Thanks Laura
I have found this question already answered at: https://stackoverflow.com/a/46692487/7654050
It is because I have not set billing up for this project. I thought it been set up as it is on my work account.
I successfully generated an access token but now I can't use it. Sadly there is no official yandex node library for using the API. There are 2 unofficial npm module that will only work with a server but I want it localhost. As example with code like this, in this case I want to display all files from my disk. Of course I enabled all scopes for my app
request.get('https://cloud-api.yandex.net/v1/disk/resources/files/', {
'auth': {
'bearer': 'xxxxxxxxxxxxxxxxxxx'
}
}, function(err,httpResponse,body){ /* ... */
if(err) {
console.log('err: ' + err)
}
console.log('body: ' + body)
});
Also if I would use https://cloud-api.yandex.net/v1/disk/resources/files?oauth_token=xxxxxxxxxxxxxx&oauth_client_id=xxxxxxxxxxxxxxxxxxx
or https://cloud-api.yandex.net/v1/disk/resources/files?access_token=xxxxxxxxxxxxxx&client_id=xxxxxxxxxxxxxxxxxxx
in my browser I would get
{"message":"?? ???????????.","description":"Unauthorized","error":"UnauthorizedError"}
Somebody has working code or an idea why I´am getting this message?
Now I'm using yandex-disk package. It works enougth for my purposes.
That my steps:
Register app in Yandex Oath Service.
After that I can get info about my app
Realize the access method to get Oath Token by calling this.
npm i yandex-disk
Inserting the code into index.js
const YandexDisk = require('yandex-disk').YandexDisk;
const disk = new YandexDisk('YourOathTokenHere');
console.log('disk', disk);
disk.readdir('/', (err, response) => {
console.log('callback error', err);
console.log('callback response', response);
});
Just include authorization header like that:
axios.get(encodeURI(`https://cloud-api.yandex.net:443/v1/disk/resources?path=${path}`), {
headers: {
'Authorization': `OAuth ${token}`
}
}).then((res) => {
console.log(res);
}).catch((err) => {
console.log(err);
});