Get list of only latest message in conversations from MS Graph API - microsoft-graph-api

I need to get a list of the last message in each conversation for o365 mail.
It appears that the odata aggregate extension (http://docs.oasis-open.org/odata/odata-data-aggregation-ext/v4.0/odata-data-aggregation-ext-v4.0.html) is not implemented. In the following query, $apply is just ignored and fails silently.
https://graph.microsoft.com/v1.0/me/mailFolders/inbox/messages?$select=conversationId,subject,createdDateTime&$apply=groupby(conversationId, topcount(1, createdDateTime))
Is there a way to get just this data without pulling back large amounts of messages and filtering out duplicate conversation ids?

If you have a last sync date, according to the docs, you can start tracking changes at an arbitrary date. You may have to deal with duplicate data if your goals can't be supported by a receivedDateTime filter.
https://graph.microsoft.com/v1.0/me/mailFolders/inbox/messages/delta?$select=conversationId,subject,createdDateTime&$filter=receivedDateTime+ge+{value}

Related

Read multiple conversations resources - ordering?

My question is about the following APIs:
https://www.twilio.com/docs/conversations/api/conversation-resource#read-multiple-conversation-resources
https://www.twilio.com/docs/conversations/api/service-conversation-resource#read-multiple-service-scoped-conversation-resources
https://www.twilio.com/docs/conversations/api/user-conversation-resource#list-all-of-a-users-conversations
What is the ordering of the conversations returned by the above APIs? Are they ordered by most/least recent activity? Most/least recent creation time? Or is the ordering undefined?
I came across this post after I had asked twilio support about how responses are ordered for
https://www.twilio.com/docs/conversations/api/user-conversation-resource#list-all-of-a-users-conversations
The response from support was they are sorted alphabetically by Conversation Sid. My limited testing confirmed the response.
I asked support to pass a feature request to the Conversations product team- allow the sort key to be included with the request.
I had to check this with the conversations team, the ordering of conversation resources is undefined and you should not necessarily rely on the order.
If you want to keep an order of conversations, particularly most recent activity, you could set up webhooks to receive updates when a message is added or updated and store that last updated time against conversation IDs in your own database and use that to order them in the client side.

How to retrieve all threads which have replies since a given timestamp?

I am ideally looking for an API that returns all the messages posted(including replies) since a given timestamp.
conversations.history is supposed to be the one I should be using, but it does not return replies, it only returns parent message (only if the timestamp of the parent message satisfies the "oldest" param I supply - i.e. if the oldest supplied in the query is later than parent's ts but earlier than replies, neither parent nor replies will be returned).
Hence, I am trying to find if there is any other API that returns the threads based on "oldest" timestamp. i.e. all the threads which have replies since a given timestamp.
Note: I looked at conversations.replies, it is only useful if you know which thread's replies you are fetching.
Currently there is no API to do what you aspire to do.
The best work around is manually fetching all threads data in-memory and then applying filter.
Did you find an alternative solution to this question? I have the same use case and when contacting Slack support I received the same response that we need to use the combination of conversations.history & conversations.replies. This will be quite an intensive and continuously growing number of calls if we need to call conversations.replies for all threaded messages just to filter out the timestamps that fit the date range. This would be catastrophic in the long run.
Ideally slack need to update conversations.replies API to support getting all replies between oldest & latest parameter just like in history.
Another alternative I am considering is to change the implementation and use the Events API instead of the Web Client API and use queueing to store all incoming messages then this will make sure that all messages are captured and stored then apply the required filters.

Get Twilio Chat User Channels sorted by last activity or unread count?

We are developing a chat system where users can be in many chat rooms, and I'd like to be able to show the most recent channels first.
This could be either by the time the last message was sent, or even by the number of unread messages, as long as there is some order and I don't need to go through all the pages of channels and get additional metadata to sort it manually.
I can't see any options in the docs and even though the response metadata has a "key" set to "channels", I haven't been able to figure out a query parameter that can change that.
It seems like channels will always be returned ordered by the random unique channel ID, so for pretty much every use case you'd need to get all channels and sort manually. Is that the case or am I missing something?
Twilio developer evangelist here.
I'm afraid you cannot order the channels within the API right now. This feature is on the roadmap though, however I can't give any time estimates for it.
The solution for now is sorting manually. I will update once that changes though.

Surveymonkey: Get all responses from a single day on a single transaction

Is there a way to get ALL the responses for a single day in one transaction for a specific survey? on the API doc, I know there is the /surveys/{id}/responses/bulk option, and even I can send the start_created_at variable.
But I think that the API response has a max number of records/data it can send, it that case, what could the solution be? Paging through the results?
I'm using the .net API, found at this site, but I can build my own wrapper if necessary.
Reference link to API doc: /Surveys/SURVEY_ID/responses/bulk
Yes you're right the /surveys/{id}/responses/bulk endpoint is what you're looking for, and you can use the start_created_at and end_created_at to filter data to a date range.
The SurveyMonkey API doesn't allow a full dump of all your data, it will always be paginated. By default it'll paginate 50 at a time, but you can change that by using the per_page GET parameter.
That max per_page varies by endpoint, for responses BULK it is 100. So you'll have to fetch 100 at a time, looping through the pages to get all your data.
One alternative is to use webhooks and set up a subscriber, that way you can get new responses in real time and fetch them one by one. That way you can keep your data updated on your side as new responses come in, rather than running a script or endpoint to bulk dump all your data. But this depends on your use case, if you're building something like an export feature, then you'll have to go through the paginated route.

Retrieve Email Sequence Number from UID Message Fetch MailCore2

Looking at Mailcore docs, I see a method to retrieve the sequence number of an email or emails by executing a fetch using the email UID. However, when looking at the Mailcore2 docs, I don't see any way to accomplish this. Is there a method for this in Mailcore2 that I am somehow not seeing, or a way to bubble up this information? I know it is possible in the command line, but I'd like to be able access it from inside my iOS app.
EDIT:
Here is why I am looking for this functionality:
We have a native iOS client that fetches the 10 newest emails at a time and saves them. Additionally, the client will fetch the next 10 older emails at a time and save them, as well as the lowest UID it has seen (minUID).
So we need to be able to continually fetch the next 10 older emails that exist on the server that the client has not yet stored or seen. (Therein lies the challenge).
Initially, we did this by fetching emails by UID in groups of 10, using our saved minUID minus 1 as the starting point for each fetch, and updating our minUID at the end of each fetch. However, as UIDs are not necessarily contiguous, the number of emails that was returned was inconsistent, and sometimes zero. To solve this problem, we thought it would be helpful to (before each fetch for the next 10 older emails), fetch the email with our stored minUID, check its current sequence number, and then fetch the next 10 older emails based on that sequence number.
To fetch messages based on a sequence number, you can use the following function syncMessagesWithFolder:folderName:requestKind:uids:modSeq:
The below example will fetch you all the new/modified messages for the folder folder above sequence number highestModSeq.
MCOIMAPFetchMessagesOperation * op = [self.imapSession syncMessagesWithFolder:folderName
requestKind:requestKind
uids:[MCOIndexSet indexSetWithRange:MCORangeMake(1, UINT64_MAX)]
modSeq:highestModSeq];
The documentation is not exactly the best place to find examples, but our wiki is increasingly becoming an excellent repository for that kind of information. What you're looking for is -[MCOIMAPSession fetchMessagesByUIDOperationWithFolder:requestKind:uids:], an example of which can be found under the IMAP examples wiki page.

Resources