I'm trying to use this method provided via the Slack API to grab the "name" attribute of the "user" object and the code I'm using to do that is as follows:
controller.hears(['users'], 'direct_message, direct_mention, mention', function(bot, message){
bot.api.users.info({}), function(err, response) {
bot.reply(message, response);
var slack_username = message["user"][2];
console.log(">>>>> " + slack_username);
});
});
I'm not sure what I'm doing wrong/missing and any help would be greatly appreciated! Thanks in advance!
EDIT:
Expected Output: "dkulas"
Terminal Output" "U"
debug: Got response null {"OK":false,"error":"user_not_found"}
degub: SAY { ok: false, error: 'user_not_found', channel" 'D0UV5S7MZ' }
The Slack API method users.info requires you to provide the Slack User ID in the query. The format is U12345678. (also see here for the usage documentation)
If you want to get the user info for a user by name, use the API method users.list to get the list of all users including name and user ID and then search that list for the right match. users.list provides all information about a user, so you don't need to call user.info.
See here for the documentation on this method.
Related
How do I delete all entries within a collection type with one request?
I have tried to use the bulkDelete endpoint: POST /content-manager/collection-types/:model/actions/bulkDelete
But it gives me the following response:
{
"error": "contentType.notFound"
}
I have also tried to pass some json parameters into the body:
{"ids": ["2", "3"]}, but its the same result.
In my example I have only one content type books, so I use book for the :model part. What am I doing wrong? I can't find any info in the documentation or somewhere else.
So for Strapi v3 the answer ist:
Because it is an internal API for the Content Type Manager, it uses the UID of the content-type, e.g. application::book.book, as also is used in the URL in the Content Type Manager (/admin/plugins/content-manager/collectionType/application::book.book?page=1&pageSize=10&_sort=id:ASC)
For v4 it should be different now.
I'm trying to create a discord bot with notification about new tweets.
I am using T.stream('statuses/filter', { follow : ['798934987978510337'] }); for this, but it show mentions too.
Can I get only tweets from user with twit?
No, the statuses/filter streaming API does contain retweets as well. You will need to filter out retweets in your own code if you do not want to pass them over to Discord.
Following code works for me. Reference https://twittercommunity.com/t/only-receive-latest-tweet-from-specific-user-twit-npm/151478
var twitParams =
{
exclude_replies: false,
count: 1,
screen_name: "your screen name excluding #"
}
T.get("statuses/user_timeline", twitParams, function(err, data, response) {
console.log(data);
});
I'd like to query the API for my Intercom.io app and get a subset of users that have a specific nested key value pair.
The client.users.listBy() works but only for keys that are a direct property of the user object, for instance client.users.listBy({ email: someUsersEmail#domain.com }) works just fine because email is a property directly on the user instance.
My user data is structured like this
user = {
...
email: someUsersEmail#domain.com,
...,
customer_attributes: {
...,
affiliate_code: 'someAffiliateCode',
...
},
...
}
and I would like to find all the users that have customer_attributes.affilate_code equal to affiliate_code: 'someAffiliateCode'.
I'd like to query the API like this:
client.users.listBy({customer_attributes.affiliate_code: 'someAffiliateCode'}, function(err, resp) {
if (err) throw err
console.log(resp)
})
But I'm getting this error
client.users.listBy({customer_attributes.affiliate_code: 'onetouch'}, function(err, resp) {
^
SyntaxError: Unexpected token .
Does anyone know how I can query the Intercom API for nested Key value pairs like in the way described above? Thank you!
As the interpreter hints, that "." in the key name is not valid JavaScript.
The only way to accomplish what you are looking for is to pre-define a Segment in the Intercom UI with "affiliate_code = onetouch". Then you can programmatically list users using that Segment ID. https://developers.intercom.io/reference#list-by-tag-segment-company
client.users.listBy({ segment_id: 'foo' }, callback);
I am very new to angualr js. I have found a very useful article about how to connect to API and use their information to show into our app using angular JS.
http://austinknight.net/weather-app-with-angular-js/
Only limitation is this weather forecast for US only. I can find many API which provided world wide forecast but I can't connect with them the way author has done here.
$http.get('https://query.yahooapis.com/v1/public/yql?q=SELECT%20*%20FROM%20weather.forecast%20WHERE%20location%3D%22' + zip + '%22&format=json&diagnostics=true&callback=')
Can someone please help me to write up such a query string based API call for any country ?
I have done sufficient research but couldn't find anything similar.
Please help.
You can pass params like this
$http.get('https://query.yahooapis.com/v1/public/yql', {
params: {
q: 'your query',
format: 'json',
diagnostics: true,
callback: ''
}
});
In the MEAN app I'm currently building, the client-side makes a $http POST request to my API with a JSON array of soundcloud track data specific to that user. What I now want to achieve is for those tracks to be saved to my app database under a 'tracks' table. That way I'm then able to load tracks for that user from the database and also have the ability to create unique client URLs (/tracks/:track)
Some example data:
{
artist: "Nicole Moudaber"
artwork: "https://i1.sndcdn.com/artworks-000087731284-gevxfm-large.jpg?e76cf77"
source: "soundcloud"
stream: "https://api.soundcloud.com/tracks/162626499/stream.mp3?client_id=7d7e31b7e9ae5dc73586fcd143574550"
title: "In The MOOD - Episode 14"
}
This data is then passed to the API like so:
app.post('/tracks/add/new', function (req, res) {
var newTrack;
for (var i = 0; i < req.body.length; i++) {
newTrack = new tracksTable({
for_user: req.user._id,
title: req.body[i].title,
artist: req.body[i].artist,
artwork: req.body[i].artwork,
source: req.body[i].source,
stream: req.body[i].stream
});
tracksTable.find({'for_user': req.user._id, stream: req.body[i].stream}, function (err, trackTableData) {
if (err)
console.log('MongoDB Error: ' + err);
// stuck here - read below
});
}
});
The point at which I'm stuck, as marked above is this: I need to check if that track already exists in the database for that user, if it doesn't then save it. Then, once the loop has finished and all tracks have either been saved or ignored, a 200 response needs to be sent back to my client.
I've tried several methods so far and nothing seems to work, I've really hit a wall and so help/advice on this would be greatly appreciated.
Create a compound index and make it unique.
Using the index mentioned above will ensure that there are no documents which have the same for_user and stream.
trackSchema.ensureIndex( {for_user:1, stream:1}, {unique, true} )
Now use the mongoDB batch operation to insert multiple documents.
//docs is the array of tracks you are going to insert.
trackTable.collection.insert(docs, options, function(err,savedDocs){
//savedDocs is the array of docs saved.
//By checking savedDocs you can see how many tracks were actually inserted
})
Make sure to validate your objects as by using .collection we are bypassing mongoose.
Make a unique _id based on user and track. In mongo you can pass in the _id that you want to use.
Example {_id : "NicoleMoudaber InTheMOODEpisode14",
artist: "Nicole Moudaber"
artwork: "https://i1.sndcdn.com/artworks-000087731284-gevxfm-large.jpg?e76cf77"
source: "soundcloud"
stream: "https://api.soundcloud.com/tracks/162626499/stream.mp3? client_id=7d7e31b7e9ae5dc73586fcd143574550"
title: "In The MOOD - Episode 14"}
_id must be unique and won't let you insert another document with the same _id. You could also use this to find the record later db.collection.find({_id : NicoleMoudaber InTheMOODEpisode14})
or you could find all tracks for db.collection.find({_id : /^NicoleMoudaber/}) and it will still use the index.
There is another method to this that I can explain if you dont' like this one.
Both options will work in a sharded environment as well as a single replica set. "Unique" indexes do not work in a sharded environment.
Soundcloud API provides a track id, just use it.
then before inserting datas you make a
tracks.find({id_soundcloud : 25645456}).exec(function(err,track){
if(track.length){ console.log("do nothing")}else {//insert}
});