I am running a Slack team for a gaming community. My users all have avatars in the game and I am already using the Slack API to automatically set their Slack user name to their in-game name, so its easier for people to be recognized.
In addition I would also like to automatically set their profile picture in Slack with their avatar picture from the game. However I could not figure out a way to do it, so my question is can it be done and if yes, how?
My current starting point is the undocumented API method users.profile.set which allows me to set the profile of a user (see below for an example of a user profile). So far I've been able to modify:
first_name
last_name
title
phone
skype
The user profile also contains the URL to the profile picture, but I was so far not able to change it. I tried external URLs, and URLs of images already uploaded on Slack.
Here is a link to my documentation of the "undocumented" Slack API method users.profile.set with all options that I could figure out so far.
Any help would be hugely appreciated.
Update November 2017
In the meantime Slack has added a new API method called users.setPhoto for setting profile photos. However, this new method does not solve this question, because it only works for your own user (or more precisely the user you have an access token for, e.g. you not specify another user ID).
I am looking for a way to change the profile pictures of all users on my Slack team by a Slack app / bot.
Example of a user profile:
{
id: "U12345678",
team_id: "T12345678",
name: "erik.kalkoken",
deleted: false,
status: null,
color: "9f69e7",
real_name: "Erik Kalkoken",
tz: "America/Chicago",
tz_label: "Central Daylight Time",
tz_offset: 3600,
profile: {
avatar_hash: "XXX",
first_name: "Erik",
last_name: "Kalkoken",
title: "",
phone: "",
skype: "",
image_24: "https://avatars.slack-edge.com/2016-03-19/XXX_24.jpg",
image_32: "https://avatars.slack-edge.com/2016-03-19/XXX_32.jpg",
image_48: "https://avatars.slack-edge.com/2016-03-19/XXX_48.jpg",
image_72: "https://avatars.slack-edge.com/2016-03-19/XXX_72.jpg",
image_192: "https://avatars.slack-edge.com/2016-03-19/XXX_192.jpg",
image_512: "https://avatars.slack-edge.com/2016-03-19/XXX_512.jpg",
image_1024: "https://avatars.slack-edge.com/2016-03-19/XXX_512.jpg",
image_original: "https://avatars.slack-edge.com/2016-03-19/XXX_original.jpg",
real_name: "Erik Kalkoken",
real_name_normalized: "Erik Kalkoken",
email: "test#email.com"
},
is_admin: false,
is_owner: false,
is_primary_owner: false,
is_restricted: false,
is_ultra_restricted: false,
is_bot: false,
has_2fa: false
}
After messing around with it for a little, it's possible to use the undocumented users.setPhoto endpoint:
curl https://slack.com/api/users.setPhoto \
-F "token=<removed>" \
-F "image=#/path/to/image.jpg"
Unfortunately it will resize your avatar which removes the ability to upload animated gifs.
I don't think the profile picture API is available yet. I read a while back that it was on their TODO list.
I was able to get it to work using Jay Querie's method.
The two difference was I gave the full path and I put the image first.
So in my case:
curl https://slack.com/api/users.setPhoto -F "image=#C:\Users\name\Pictures\dojocat.jpg" -F "token=xxxx-123-123-123-123"
Originally when I was using gitbash to run the curl and it was searching for the image in the directory where my gitbash was installed / being executed. So if I put the dojocat.jpg next to my gitbash executable it would would have found it.
Related
I am trying implement active_model_otp on a sample rails application.
My user model has name and email columns. After following the necessary steps from the documentation I first created a user as follows on rails console:
User.create(name: "Abc", email: "example#email.com")
This created a record as follows:
<User id: 1, name: "Abc", email: "example#email.com", created_at: "2017-04-28 07:12:25", updated_at: "2017-04-28 07:12:25", otp_secret_key: "lol6rrtqppy46xfs">
Then I assigned:
user = User.last and
user.otp_secret_key gave the otp that was generated which is
=>"lol6rrtqppy46xfs"
Then I ran
sleep(2)
According to given documentation it supposed to generate a new otp after 2 seconds. But when I gave: user.otp_secret_key again in the console after 2 seconds it is returning the same old otp.
=>"lol6rrtqppy46xfs"
What am I missing ?
Twilio developer evangelist here.
The otp_secret_key is the string that is used to generate the actual OTP code that you send to the user. It is the secret that is shared to the user (via the QR code) and so it needs to match on both the user's auth app as well as your server.
The generated OTP should change every 30 seconds. As far as I can see it uses the default interval of the ROTP gem, which is 30 seconds.
The method to get the OTP is otp_code. So to check it's working, try:
user = User.last
puts user.otp_code
sleep(30)
puts user.otp_code
Let me know if that helps at all.
I'm trying to use the FB Events API (v1) to publish events which works great.
https://developers.facebook.com/docs/graph-api/reference/v1.0/page/events
Everything works... except, I can't get the no_feed_post method to work.
The Event posts perfectly, but the feed/wall post is NOT suppressed like it's supposed to be.
params = { name: "Blah # #{place.name}", description: event.prizes, location: '123 Blah St.',
start_time: Time.current, no_feed_story: true }
I have tried setting no_feed_story to:
true
1
"true"
t
Nothing seems to work... what does Facebook want?
Scanning the docs on facebook, they indicate these are the valid fields.
name
start_time
end_time
description
location
location_id
privacy_type
I don't see no_feed_story as a POST option
Please also make note there is a note that states:
This document refers to an outdated version of Graph API. Please use the latest version
I feel like a lot of the documentation on this is outdated, but this is what I have been trying so far:
I am using the ActiveMerchant::Billing::PaypalExpressGateway gateway.
First I setup the purchase and redirect the user to Paypal:
response = gateway.setup_purchase price,
return_url: <confirm url>,
cancel_return_url: <cancel url>,
items: [
{
name: 'My Item',
quantity: 1,
description: "My Item Description",
amount: price
}
]
redirect_to gateway.redirect_url_for(response.token)
This works, I can sign in as a sandboxed buyer and confirm the payment, which brings me back to <confirm url> from above. In the confirmation, I do:
response = gateway.recurring price, nil,
token: params[:token],
period: 'Year',
frequency: 1,
start_date: Time.now,
description: 'My Item Subscription'
When I do this, I receive an invalid token error from Paypal in the response variable. The token seems to be fine, it is present in the URL when I am brought back to the confirmation URL. I'm then taking it directly (params[:token]) and sending it back to Paypal.
Am I doing something completely wrong? Like I said, it seems like a lot of the documentation for this type of process is outdated (or maybe what I am trying is the stuff that is outdated...)
After looking through the source code for ActiveMerchant's Paypal express checkout gateway, I came to the conclusion that it's simply outdated when dealing with recurring payments. I switched to the paypal-recurring gem instead and everything worked fine.
I'm trying to create a new event using the Koala gem and it's returning with the same error I got when I tried to update an event with an incorrectly formatted datetime value.
I can update just fine now but still cannot create an event.
Here's the code I use on my update method which works:
start_time = safe_params[:start_time].in_time_zone
end_time = safe_params[:end_time].in_time_zone
graph.put_connections(safe_params[:fb_id], "event", {
name: safe_params[:name],
description: safe_params[:description],
privacy: safe_params[:privacy]
})
And here's the code I'm trying to use to create a new event object:
graph.put_connections("/me/events", "event", { #this is the line that errors
name: safe_params[:name],
description: safe_params[:description],
privacy: safe_params[:privacy]
})
According to Facebook's documentation on creating an event (https://developers.facebook.com/docs/graph-api/reference/user/events/), I should be able to create a new event just by initiating a post to /me/events. Anyone have any idea?
I also tried:
graph.put_connections("/"+current_user.fb_id.to_s+"/events", "event", {
Thanks!
What happens if you do something like this?
graph.put_connections("me", "events", {
name: safe_params[:name],
description: safe_params[:description],
privacy: safe_params[:privacy],
start_time: ...,
end_time: ...
})
So after messing with Facebook's Graph Explorer and attempting hundreds of different combinations with put_connections I decided to make a straight graph_call using Koala.
Finally got an ID response back. I almost cried. Thought I'd share with the community in case there's someone else trying to do the same thing.
event_response = graph.graph_call("/me/events",{
name:safe_params[:name],
start_time: safe_params[:start_time],
privacy_type: safe_params[:privacy],
access_token: current_user.oauth_token}, "POST")
safe_params[:fb_id] << event_response["id"]
#event = Event.create safe_params
I make the call in a stored variable event_response because the Facebook Id returned is used in my app.
First thing I found out: despite using "privacy" as the name of the privacy field when GETting from Facebook and saying so in their documentation, "privacy_type" is actually what you want (found this out in another SO post).
The second thing I found out is even though you are authenticated (have a user token) when you make a graph_call you STILL need to pass along the current_user access token along with making a POST graph_call.
Hope this helps someone!
Does anyone know why the picture attribute is not working in following Facebook UI call?
function postToWallUsingFBUi()
{
var data=
{
method: 'stream.publish',
message: "Posted using FB.ui and picture.",
display: 'iframe',
caption: "Caption",
name: "Name",
//ver 1 picture: 'http://www.somedomain.com/albums/s339/rockaja/fb-520.png',
//ver 2 picture: '#Url.Action("Action", "Controller", new { PageId = Model.PageTabId }, Request.Url.Scheme)',
picture: 'https://localhost/MyVirtualDirectory/Controller/Action/283659015078395',
link: "http://www.mydomain.com/", // Go here if user click the picture
description: "Description field",
actions: [{ name: 'action_links text!', link: 'http://www.mydomain.com' }]
}
FB.ui(data, onPostToWallCompleted);
}
As you can see the picture attribute uses a picture from localhost. If i paste this URL into the browsers's Address field, i get the picture as expected.
I also commented out other two versions:
version 1 is working properly as expected, but
version 2 is not working (this is an ASP.NET MVC call, but that fact does not affect the result).
May be it is due to the fact that i request a localhost-ed picture?!
I have never worked on FB API so take my suggestion with a pinch of salt.
Based on my understanding of how Facebook works, whatever pictures you share on user's wall go into FB's data store first and are always pulled from that store.
Here, The Facebook API may be downloading the picture from the URL you have provided and push it into it's own store before publishing it on user's walls. When you use a localhost url, then the call to download the picture would obviously fail.
There must be another version of the API where you should be able to send the picture content as byte array. If there is, then you can load the picture from disk yourself and send the byte array in the API