My bot replies is being marked as "show additional replies..." - javascript

Hi I’m building a bot which posts message from students as a campaign on twitter. I wrote the bot using Node.js
My problem is that the bot replies with a phrase (it’s not a link or a media, just text without explicit words) but Twitter is marking these messages as “Show additional replies, including those that may contain offensive content”.
I marked the button on privacy setting for “Display media that may contain sensitive content” but it doesn't seem to change it. Anybody knows what’s wrong?? I appreciate your help.
Here is a screenshot of how the replies are showing for reference:
Image with sensitive content block
Here is some of the code I'm using to post the tweets:
Bot.get('search/tweets', { q: '#orgullopucp -filter:retweets', since_id: last_mention_id }, function(err, data, response) {
if (err){
console.log('Error!', err);
return false;
}
/* Next, let's search for Tweets that mention our bot, starting after the last mention we responded to. */
if (data.statuses.length) {
console.log(data.statuses);
data.statuses.forEach(function(status) {
console.log(status.id_str);
console.log(status.text);
console.log(status.user.screen_name);
/* Now we can respond to each tweet. */
Bot.post('statuses/update', {
possibly_sensitive:false,
status: '#' + status.user.screen_name + ' ' + random_from_array(sentences),
in_reply_to_status_id: status.id_str
}, function(err, data, response) {
if (err){
/* TODO: Proper error handling? */
console.log('Error!', err);
}
else{
fs.writeFile(__dirname + '/last_mention_id.txt', status.id_str, function (err) {
/* TODO: Error handling? */
if(err){
console.log('Error!', err);
}
});
}
});
});
} else {
/* No new mentions since the last time we checked. */
console.log('No new mentions...');
}
});
});
response.sendStatus(200);

Related

Why does this javascript code not redirect the user after the metamask transaction?

I want to make a javascript code that does a metamask transaction and redirects the user to another page after the transation is completed. How easy this may sound, I can not figure it out.
My current code lets the user complete the transaction, but it does not redirect the user to another page. Instead, it gives this error: "MetaMask - RPC Error: invalid argument 0: json: cannot unmarshal non-string into Go value of type common.Hash"
I have looked it up, but I could not find any possible fix for my problem.
This is my code:
try {
// send the transaction
ethereum.send({
method: 'eth_sendTransaction',
params: [
{
to: contractAddress,
from: userAddress,
value: amt
},
],
}, (error, transactionHash) => {
if (error) {
console.error(error);
} else {
// check the status of the transaction using the transaction hash
ethereum.request({
method: 'eth_getTransactionReceipt',
params: [transactionHash],
}).then((receipt) => {
// check if the transaction was successful
if (receipt.status === '0x1') {
console.log(`Transaction was successful`);
// redirect to another page
window.location.href = "page.php";
} else {
console.log(`Transaction failed`);
}
}).catch((error) => {
// This is the line of code the error is assigned to:
console.error(error);
});
}
});
} catch (error) {
console.error(error);
}
});
} else {
document.getElementById("bericht").innerHTML = "Install Metamask before you continue";
return;
}
I have tried looking the error up on internet, but nothing significant showed up. Could anyone help? Thank you in advance!

How to set an object as nullable in Javascript (NodeJS)

I keep getting an error: TypeError: Cannot read property 'doors' of null. I want to be able to set doors to be nullable, as to be able to avoid this error and simply hit the error response and return 404. However, I am not sure how to do this?
Here is my code:
Data.findOne({
'_id':'6182544c20d538aefe49def0',
'doors.id':doorId
}, {
'doors.$':1
}, function(err, data) {
if (err) {
res.status(404).send('No Matching Door Found')
} else if (data.doors[0].status === 'open') {
res.status(401).send('Door already unlocked')
} else {
res.status(200)
}
})
The error is hit on the third line, where It cannot find a doors object where the ID is equal to doorId.
I have tried setting doors.id to !doors.id, however, this then kept hitting the 404 regardless of what was being entered.
Any help is appreciated, thank you.
Well it seems that your entire query is wrong.
I would suggest first to try this query for your needs:
Data.findOne({
'_id':'6182544c20d538aefe49def0',
'doors.id':doorId
}, {
'doors.$':1
}).exec(function(err, data) {
if (err) {
res.status(404).send('No Matching Door Found')
} else if (data.doors[0].status === 'open') {
res.status(401).send('Door already unlocked')
} else {
res.status(200)
}
})
Then I recommend you to read more about MongoDB and Mongoose.

How to change order of mail folders?

I have this function for getting user folders.
function getUserFolders(callback) {
getAccessToken(function(accessToken) {
if (accessToken) {
// Create a Graph client
var client = MicrosoftGraph.Client.init({
authProvider: done => {
// Just return the token
done(null, accessToken);
}
});
// Get all folders
client
.api("/me/MailFolders")
.orderby("")
.get((err, res) => {
if (err) {
callback(null, err);
} else {
callback(res.value);
}
});
console.log(client);
} else {
var error = { responseText: "Could not retrieve access token" };
callback(null, error);
}
});
}
When I get a response back, the order of folders is:
I have read documentation and couldn't find how to change order of folders. The order i would like to have is the same one as on outlook. Thank you for your help!!
You cannot retrieve folders in the order a user organized them in a given client.
I'm also not sure what you expect to get from .orderby(""). Unless you provide a field to order by, it won't know how you want to sort them.

Twitter video upload with NodeJS

I am trying to post a video using Twitter modules in NodeJS but I am getting an error - Error 202 “Your credentials do not allow access to this resource”.
Here a snippet of code, it is missing the APPEND and FINISH calls etc but would have expected not to receive an error 202?
Has anyone managed to upload a video using JavaScript than can give me some guidance? I have tried to research and tried several different options.
T.post('media/upload', {
media: data,
encoding: 'base64',
command: 'INIT',
total_bytes: getFilesizeInBytes(image)
}, function(error, media, response) {
if (!error) {
var status = {
status: message
};
if(media) status['media_ids'] = media.media_id_string;
T.post('statuses/update', status, function(error, tweet, response) {
if(!error) console.log(' -- message sent');
else console.log(error);
});
} else {
console.log(error);
}
});

How to watch for new records added to model in Sails.js

I'm trying to push a message for when a user sends a message to a certain certain Id (within an User model) in a user to user chat messaging system. I can't get it to work, nor do I know how to get started. I have this in my Messaging controller:
sendAndReceiveMsgs: function(req, res) {
if (req.isSocket && req.param('message') && req.param('to')) {
var message = req.param('message'),
from = req.user.id,
to = req.param('to');
Messaging.create({ message: message, from: from, to: to })
.exec(function (err, created) {
console.log('sent');
});
} else if (req.isSocket) {
Messaging.find({ where: { to: req.user.id }, limit: 1, sort: 'id DESC' })
.exec(function(err, messages) {
if(messages.length > 0){
console.log(message.length + " new messages");
} else {
console.log("No new messages");
}
Messaging.subscribe(req.socket, message);
Messaging.watch(req);
Messaging.publishCreate({ id: message[0].id, message: message[0].message });
});
} else if (!req.isSocket) {
return res.notFound();
}
}
However, it doesn't push further new messages to the user (meant for him). Any clue? I really don't understand this, and don't know where to go from here. Thanks!
Please show the client side code too.
One thing I noticed is that you're using subscribe but it's used only to see messages emittted by .publishUpdate(), .publishDestroy(), .publishAdd() and .publishRemove(). Not sure if that helps
You need to use io.socket.on in your client. See the documentation here.
The eventIdentity if your using pub/sub methods are also the model name.

Categories

Resources