GitHub API : Get thread_id from mail notifications (issues, pull requests, ...) - api

I'm currently working on a project using the GitHub API and ThunderBird.
On this project I need to work with notifications and threads.
In order to get a thread_id needed for some requests (such as GET /notifications/threads/{thread_id}), I can use the GET /notifications api route which returns an array of notifications with the id of the threads they belong to.
The problem is, I don't want to get the thread_id that way but directly from the mail you received when you are mentioned on a thread, for instance : an answer to an issue you asked.
Normally you get a mail that looks like that :
mail notifications from GitHub.
Unfortunately, I could not find the thread_id in the mail (headers, content, ...), the closest thing i could find was the link "unsubscribe" at the end, which leads to the thread.
This url contains what seems to be an id but it's not an int and it looks like it's encoded in some base...I tried base64 but the int returned is not working (it's different than the id you get with /notifications of the API).
So my question is : is there a way to get the thread_id directly from the mail so that I can use it in my project to request the GitHub API ?
Thank you,

Related

how to find a username with the github api

I've made an application that creates pull requests to update the dependencies in all of my org's repos when the repo "Alpha" gets a new tag. The process is triggered by our CI flow on Alpha. Other engineers here would like to upgrade this application so that whoever made the tag is also automatically added as a requested reviewer to all of the associated pull requests. I do not see any way to do this with the github REST api. So far I have:
GET tag by name -> tag object sha
GET tag (with obj sha) -> tagger name & tagger email
*************GAP**************
POST requested reviewer (with username) -> completed!
I can't see any good way to get a username from the REST api with the name and/or email. I could query commits from Alpha and filter them, BUT "person who tagged" != "person who made last commit AND I know that at least one of our more prolific taggers is sometimes logged in from different emails (web vs cli vs home machine, etc), so the app might miss them from time to time.
I think it may be possible to get what I want via the GraphQL api, but I'd really like to exhaust REST possibilities before I go down that road. Please shoot any ideas my way!
After gathering more information, it looks like it's possible, and even slightly more elegant than I anticipated. If I have the name of the tag (the 'ref'), I can get a specific commit with that rather than the SHA. the response for this commit includes author information that gives the login. I can then use this along with the pull number to request a reviewer.

Hangouts/Chat - messagesUnread always 0 despite new messages

I'm trying to write a Hangouts/Chat dockapp to show unread message notifications, I'm using the following scope url:
https://www.googleapis.com/gmail/v1/users/me/labels/CHAT?access_token=<my_access_token>
The json returns fine, however messagesUnread is always 0. I've disconnected every possible app/browser etc that could be grabbing the messages before I reloaded the above URL, sent a new chat message from another account and messagesTotal increments by 1 but still the unread stays at 0. Even if I disable hangouts in the gmail web interface settings, send a message and search by "label:chat" the chat message that was received arrives marked as read in the web interface. If I manually mark a chat message as unread then the values in the above url do change correctly.
I can obviously work around this by storing he previous messagesTotal on comparing to current, however that creates a requirement to click the app to acknowledge the unreads which is a tad annoying.
Has anyone found a way to get a true unread count from chats/hangouts?
Thanks,
Haydn.
If you use the method users.labels.get for any other label (e.g. INBOX), it will return messagesUnread correctly.
Unfortunately for the label CHAT this is not the case
Chat messages are not quite the same as emails
It is not clear either it is intended behavior that you cannot retrieve the unread chat messages or a bug
This issue has been already filed on Google's Public Issue Tracker, but it has been closed by Google because it has been reported in Spanish.
Feel free to report the issue in English to hopefully obtain a response from Google eihter the bheavior is intended or a bug.

How can I search for messages (embeds) with a particular 'author' through DiscordSocketClient?

I'm in the process of building a new Discord bot (of course), and I've been working on the Twitter integration using Tweetinvi. I've got most of the Twitter streaming bits working normally (at least, as far as I can tell in my simplified testing), but I wanted to have the bot modify/delete posts in Discord if the Tweet is subsequently deleted. Tweetinvi has a TweetDeleted event that I can use to detect this as a part of my stream, but I'm having difficulty figuring out how to find the post in Discord.
What I'd like to do is "simply":
Search for posts (embeds) from the author (defined by the original Tweet)
Find the post with a matching .Url value in the embed
Replace that post with a message like "THIS TWEET WAS DELETED".
The problem I'm running into, however, is I can't seem to find a way to do "step 1" - search for and return any posts from the specified author. The only option I've found so far is the GetMessagesAsync method, but that doesn't seem to have a way to filter the results. Plus, with the "soft limit" of 100 messages, I worry that I could still not find the message I'm looking to delete.
I post the embeds using the DiscordSocketClient object in my class like this:
Me.A1FDiscordClient.GetGuild(Server.ID).GetTextChannel(PostingChannel).SendMessageAsync(MessageText.Trim, False, TweetBuilder.Build)
I had started working on something similar for the deletion/modification, but I think I'm simply spinning my wheels at this point:
Dim Messages = Me.A1FDiscordClient.GetGuild(Server.ID).GetTextChannel(PostingChannel).GetMessagesAsync(100)
I'm probably being dense and/or completely overlooking something, but I'm not even sure what to do with this once I have it. I was looking at using the .Select(Of TResult), but I think I've just gotten myself too twisted. I don't necessarily need a whole solution, but I could really use someone giving me a nudge in the right direction.
Discord does not provide an endpoints for Bots to search/filter on specific criteria. The only way to retrieve messages is to use the GetMessagesAsync() method
The limit for GetMessagesAsync() is technically Int32.MaxValue. The 100 that you see is simply the default. This is because Discord will return in chunks; 100 messages at a time. For example if you set the limit to 1000, you will get 10 chunks of 100.
Possible issues with retrieving a large number of messages? The main issue would be the length of time taken to retrieve the messages, which could block the gateway unless offload the process to its own task.
A possible solution would be to implement your own system for linking and storing twitter posts to discord posts. Could be as simple as a dictionary of Twitter post id and discord post id which would allow you to easily find the message id related to a given twitter post.

Worklight api console request for Push

I need to get a list of users for a specific Push adapter/event source, and, I'm trying to use the API console requests, which says the format is:
http://{hostname}:{port}/{context-root}/console/api/{api-context}/{action}/{parameters}
and I'm using:
http://192.168.1.106:10080/Module_07_04_nativeAPIForiOSPush/console/api/Push/get/PushAdapter/PushEventSource
to search the demo project, which has one subscriber. However, I get 404 return from a browser request.
The first column of the docs is the "api-context", but, it lists "Push" and "Event Sources", which, obviously seems invalid.
What is the correct format to find users subscribed to a push for a specific adapter/event source?
WL server does not provide API for listing subscribed users. By design you should maintain your own DB of subscribed users, this is why you have onSubscribe onUnsubscribe callbacks in event source. As an alternative - you can look into WL's DB tables to find this info.

Google Contacts API 404 photo upload

Using the Contact API v3 I had a working implementation for uploading a photo to an existing contact.
Since a couple of weeks this fails with 404. The implementation has not been changed when the API servers started to sent back 404s and I don't see any indication what exactly changed and would result now in the 404s.
I'm using HTTP PUT + the photo URL of the contact.
One interesting observation I made was that the contact's self-URL changes which each request (the provided details are still always the same and correct).
Did anyone notice something similar ?
Edit: Link to issue: http://code.google.com/a/google.com/p/apps-api-issues/issues/detail?id=3301&q=contact&colspec=API%20ID%20Type%20Status%20Priority%20Stars%20Opened%20Summary
tried different photo formats and sizes, different content types and even photos which had been uploaded previously (when it was still working). Nothing changed the behaviour of returning 404.
w.r.t to change contact ids: the contact ID changes between API invocations. I first thought it could be related to reopened connection( no keep-alive) that contact ids change. However what speaks against this being the cause of the issue is that first retrieving a contact and then editing a contact's address is possible without any issues.
authentication does not seem to be problem as well - otherwise editing a contact's address would not work as well.
PS: I'm using the JSON output format when retrieving the contact.
PS2: s/GET/PUT in step 3 ( I tried to change PUT to GET to see if it still returns 404... which it does).
PS3: am not using any client library but implement the protocol directly (which should not be relevant for the HTTP PUT on the photo link
After hours of investigation I found out that this is particular an issue using OAuth1. Using OAuth2 the exact same photo links which had been returned when requesting a specific contact record using OAuth1 work and return the photo data on HTTP GET. I expect HTTP PUT for photo links using OAuth2 to succeed as well.
Remains open if if there's some kind of workaround for OAuth1.