Domains are not being added, Whitelist domains facebook messenger extension - node.js

I've been trying to whitelist my domains following the instruction that is given by facebook but nothing is working.
I first tried with curl, the response is {result:"success"} but when I try to list the domains that are whitelisted I am getting {data:[]}
Then I tried using node request module as follow:
request.post("https://graph.facebook.com/v2.6/me/messenger_profile?access_token=sfdlksdfu79r9429049824982342348sjdfsf", {
"setting_type": "domain_whitelisting",
"whitelisted_domains": ["https://mydomainw.com", "https://mydomainw.com/profile", "https://sfujyx.com/ofr", "mydomain1.com", "mydomain.com"],
"domain_action_type": "add"}, function (err, res, body) {
console.log("Whitelisting domain");
if (!err) {
console.log(body);
console.log("Showing the list of whitelisted:");
request.get("https://graph.facebook.com/v2.6/me/messenger_profile?fields=whitelisted_domains&access_token=sfdlksdfu79r9429049824982342348sjdfsf", function (err, res, body) {
if (!err) {
console.log(body);
} else {
console.log(err);
}
});
} else {
console.log(err);
}
});
Still it bring the same result as curl :
And when I use Facebook Graph Api Explorer tool, here is the error I am getting:
I am really stuck, I don't know what should I do or how people exactly whitelist domain for messenger extension.
What I am doing wrong? why isn't the domains being added?
My project is on Google App Engine.

The problem is I was using the App Access Token instead of the Page Access Token, I didn't know the difference.

your domain: "https://mydomainw..com" is an invalid domain.
The request should return:
{
"error": {
"message": "(#100) whitelisted_domains[0] should represent a valid URL",
"type": "OAuthException",
"code": 100,
"fbtrace_id": "Aq3AVaNVJU9"
}
}

Actually, I didn't use "setting_type" before. This is how I register domains:
var request = require("request");
var options = { method: 'POST',
url: 'https://graph.facebook.com/v2.6/me/messenger_profile',
qs: { access_token: 'my_page_token' },
headers: { 'content-type': 'application/json' },
body:
{ whitelisted_domains:
[
'https://mydomainw.com',
'https://ijuugwivbc.localtunnel.me' ] },
json: true };
request(options, function (error, response, body) {
if (error) throw new Error(error);
console.log(body);
});

Related

I keep running into this error when trying to call a register_url using daraja, a safaricom api for a c2b request. I am building the app with node js

**I am met with this error when calling a register_url, **
{"Envelope":{"encodingStyle":"http://schemas.xmlsoap.org/soap/encoding/","Body":{"Fault":{"faultcode":"soap:Server","faultstring":"Execution of ServiceCallout SC-SearchURL failed. Reason: ResponseCode 503 is treated as error","faultactor":{},"detail":{"source":{"errorcode":"steps.servicecallout.ExecutionFailed"}}}}}}{"Envelope":{"encodingStyle":"http://schemas.xmlsoap.org/soap/encoding/","Body":{"Fault":{"faultcode":"soap:Server","faultstring":"Execution of ServiceCallout SC-SearchURL failed. Reason: ResponseCode 503 is treated as error","faultactor":{},"detail":{"source":{"errorcode":"steps.servicecallout.ExecutionFailed"}}}}}}
Here is the code
router.get ('/register', getaccess_token,(req, res)=>{
let url = "https://sandbox.safaricom.co.ke/mpesa/c2b/v1/registerurl";
let auth = "Bearer "+ req.access_token;
request(
{
url :url,
method : "POST",
headers:{
"Authorization":auth
},
json:{
"ShortCode": "600730",
"ResponseType": "Completed",
"ConfirmationURL": "https://be71-196-207-148-228.ap.ngrok.io/daraja/confirmation",
"ValidationURL": "https://be71-196-207-148-228.ap.ngrok.io/daraja/validation"
}
},
function (error, response, body) {
if (error) {
console.log(error);
} else {
res.status(200).json(body);
}
}
)
});
getaccess_token, is a a function that calls an access token
I have changed the short code that didn't work
2 I have made hosted the confirmation/validation url and made sure its https
3 I have gone to the docs but

How to update a pull request by GitHub APP API?

I developed GitHub APP to manage pull requests process, I'm using two APIs
1. statuses check API
2. update-a-pull-request API
I get this error message when a request to update an existing pull request that was created by one of the users.
How I can get installation token with the right permissions?
{
"message": "Validation Failed",
"errors": [
{
"message": "Only the pull request author may change the maintainer_can_modify value",
"resource": "PullRequest",
"field": "maintainer_can_modify",
"code": "invalid"
}
],
"documentation_url": "https://developer.github.com/v3/pulls/#update-a-pull-request"
}
To execute API call, I need token, I generated the token in this way:
Created app in GitHub Account
Created a private PEM key in the APP
In code, created JWT token using PEM key
Using the JWT token to create installation token as below
Header
function generateJwtToken() {
return jsonwebtoken.sign(
{
iat: Math.floor(new Date() / 1000),
exp: Math.floor(new Date() / 1000) + 60,
iss: ISSUER_ID,
},
PEM,
{algorithm: 'RS256'},
);
}
let githubHeadersToAccessToken = {
'User-Agent': 'nodejs',
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + generateJwtToken(),
'Accept': 'application/vnd.github.machine-man-preview+json'
};
Get Installation token
payloadToken = {
"repository_ids": [
],
"permissions": {
"pull_requests": "write",
"statuses": "write",
"administration" : "write",
"organization_administration": "write",
"contents": "write",
"team_discussions": "write",
}
};
request.get({
url: 'https://api.github.com/app/installations',
headers: githubHeadersToAccessToken
}, function optionalCallback(err, httpResponse, body) {
if (err) {
return console.error('Connected App get token failed:', err);
}
console.log('APP Installation id');
console.log('Installation id: ' + JSON.parse(body)[0].id);
app_installed_id = JSON.parse(body)[0].id;
request.post({
url: 'https://api.github.com/app/installations/'+app_installed_id+'/access_tokens',
headers: githubHeadersToAccessToken,
json: payloadToken
}, function optionalCallback(err, httpResponse, body) {
if (err) {
return console.error('Failed to get access token to GitHub: ', err);
}
//console.log(body);
console.log('Access token to GitHub: ' + body.token);
});
});
Update existind pull request that was created by one of the users
request.post({
url: 'https://api.github.com/repos/'+owner+'/'+repo+'/statuses/'+sha,
headers: githubHeadersApiV3,
json: {
"state": status,
"context": "PR <> GUS Validation"
}
}, function optionalCallback(err, httpResponse, body) {
if (err) {
return console.error('Connected App get token failed:', err);
}
//console.log(body);
console.log('commit sha: ' + sha + ' updated with status: ' + status);
});
I want to update that the code is working, I can update pull request using Github APP.
The problem I mentioned happen when I try to change "maintainer_can_modify" in pull request, which is not allowed, only by owner, then I just removed it.
But in my case I wanted to add comment, change title, etc ..
I will leave this question as an example for building GitHub app to update pull request using NodeJS.

Discord Profil Picture Update from ElectronJS using request PATCH

I'm trying to code an application into Electron JS to allow the person to change their profile picture at the same time on several applications.
For this I use the APIs of each platform.
For Twitter it works correctly, but I block at the level of Discord.
I can make a GET request on the profile, but I can't do a : PATCH/users/#me
https://discordapp.com/developers/docs/resources/user#modify-current-user
I do not know if it's the token that does not offer enough power, because I only asked for Identity as permission on my application.
I tried to pass JSON between true and false,
to add a content type, but I still have the same answer: {code: 0, message: '401: Unauthorized'}
function postDiscord(image) {
const imageDataURI = require('image-data-uri')
let {token} = store.get('discordToken') //get stored token
imageDataURI.encodeFromFile(image)
.then(res => {
request({
method: 'PATCH',
url: 'https://discordapp.com/api/v6/users/#me',
headers: {
'Authorization': 'Bearer '+token,
'User-Agent': 'someBot (site, v0.1)'
},
body: {
'avatar': res
},
json: true
}, function(err, res) {
if(err) {
console.error(err);
} else {
console.log(res.body)
}
}
);
})
}
{code: 0, message: '401: Unauthorized'}
Refering to Discord :https://github.com/discordapp/discord-api-docs/issues/1057
Cannot upload new pics with Oauth :/

node.js request multi line

Google analytics measurement protocol says to use multiple lines for their /batch endpoint:
https://developers.google.com/analytics/devguides/collection/protocol/v1/devguide#batch
POST /batch HTTP/1.1
Host: www.google-analytics.com
v=1&tid=UA-XXXXX-Y&cid=555&t=pageview&dp=%2Fhome
v=1&tid=UA-XXXXX-Y&cid=555&t=pageview&dp=%2Fabout
v=1&tid=UA-XXXXX-Y&cid=555&t=pageview&dp=%2Fcontact
How would I do something like that with node.js and request? Here's my current code for /collect
request.post(
'http://www.google-analytics.com/batch',
{ form: { v:1,tid:'UA-xxxxx-1',cid:event.queryStringParameters.cid,t:'event',ec:'xxx',ea:"xxx", el:"xxx", ev:"xxx", dr:'xxx'} },
function (error, response, body) {
done(null,'Check for GA event');
}
);
Combine each line in a single string, separated by "\n".
const request = require("request");
request({
url: "http://www.google-analytics.com/batch",
method: "post",
body: "v=1&t=pageview&tid=UA-XXXXXXXX-X&cid=555&dl=https%3A%2F%2Fmydomain.com%2Ftest&dt=Test\nv=1&t=pageview&tid=UA-XXXXXXXX-X&cid=554&dl=https%3A%2F%2Fmydomain.com%2Ftest2&dt=Test2"
}, function(error, response, body) {
if (error) { console.log(error); }
});
Your real-time report will show 2 active users on 2 different pages.

Permission issue on /{page-id}/conversations with Facebook Graph API

I'm working with Facebook Graph API and can't figure out why I can't accept the following route : /{page-id}/conversations
When I do I receive the following error : (#283) Requires extended permission: manage_pages
Here is the way I get my token :
First I get an acces_token for the user using the usual login, I ask for ['read_page_mailboxes', 'manage_pages']as permissions.
With this access token I call /me/accounts to get the list of pages for this user. In my case the user only have a single page, from this page I take the ID and access_token.
Being able to retrieve an access_token for the page means thaht the manage_pages permission is indeed granted.
Then I try to call /{page-id}/conversations with the page access_token and I face the error mentioned earlier.
Here is a snippet for node.js which is basically what I do in my app in a single function :
var options = {
url: getFbUrl('/me/accounts'),
qs: { // Query string parameters
access_token: userAccessToken,
},
method: 'GET'
};
request(options, function (err, response, body) {
if (err)
return done(err);
body = JSON.parse(body);
var pageAccessToken = body.data[0].access_token,
pageId = body.data[0].id;
var pageOptions = {
url: getFbUrl('/' + pageId + '/conversations'),
qs: {
access_token: pageAccessToken
},
method: 'GET'
};
request(pageOptions, function (err, response, body) {
if (err)
return done(err);
console.log(response.statusCode);
console.log('PAGE BODY', body);
done();
});
});
I've been stuck on this for way longer than I'd like, any help or tips appreciated.
Have a nice day.
It's a reported bug and here is the link: https://developers.facebook.com/bugs/380833342117530/

Resources