Setting up Gmail Push Notification for a specific email having attachments - gmail

I am trying to set up Gmail Push Notification to create a watch request for any new email received in the INBOX. So far, this is fine. However, I am trying to create a watch request as described here :
https://developers.google.com/gmail/api/guides/push#getting_gmail_mailbox_updates
I would like to set up a watch request for any email received from a specific email(info#abc.com) address having a subject line "[Important]" and having a PDF attachment.
Any idea if such a watch request can be set up?
Currently, I am reading all the emails from INBOX using imaplib received in the last 24 hours and manually search for emails having the subject line and attachment. However, I believe, this solution is not ideal.

Issue:
The only filter you can apply to Gmail Push Notifications is which label/s to retrieve notifications from, as can be seen here. Because of this, the filtering of messages depending on (1) who sent the message, (2) the email subject and (3) whether the email has a certain PDF attachment cannot be done at this stage, but after receiving the notifications. Luckily, though, there is no need to look for these messages manually, you can code your application to do that for you.
Workflow:
- Step #1. Set notifications for all INBOX and retrieve startHistoryId: As was said before, you have to receive notifications for all INBOX, since there is no more specific filter available. A call to Users: watch, providing INBOX in the labelIds field and the topic you created in topicName, will effectively configure the notifications. The response to watch has this shape:
{
historyId: 1234567890
expiration: 1431990098200
}
Where historyId refers to the mailbox’s current state. Let’s store it somewhere, and call it startHistoryId.
- Step #2. Get INBOX changes: After completing step 1, whenever there is a change in your INBOX, your application will receive a notification message describing the change. Whenever a notification is received, you want to get information about the specific changes made to the INBOX, and to achieve that, you should call history.list().
That is to say, your application should call history.list() every time a notification is received. Now, you want to get changes since last time, and that’s why you should provide the historyId retrieved in step 1 as the parameter startHistoryId. If you want to only retrieve new messages (and not deletions, or label edition/removal), you can set historyTypes to messageAdded. The request could be like this:
{
userId: “your-email-address”,
historyTypes: “messageAdded”,
startHistoryId: “your-start-history-id”
}
As a response, you’ll get something like this:
{
"history": [
{
"id": unsigned long,
"messages": [
users.messages Resource
],
"messagesAdded": [
{
"message": users.messages Resource
}
]
}
],
"nextPageToken": string,
"historyId": unsigned long
}
Here, you should retrieve historyId, which will be used as startHistoryId the next time history.list() is called, and messagesAdded, which contains the IDs of the new messages you want to look for (only ID and threadId seem to be populated).
- Step 3. Filtering messages: Now you have the list of message IDs that have changed since last time (messagesAdded), and you want to know which of them match your criteria. To know that, you’ll have to iterate through all IDs in messagesAdded and call Users.messages: get for each ID. This will return the corresponding message resource. For each message, you’ll have to check whether the criteria are met:
Sender email: inside the resource, access the headers (message[“payload”][“headers”]), and loop through them, looking for the one whose name is From. You have to check whether the corresponding value is the email you’re looking for.
Subject: as in step (a), access the headers and look for the header whose name is Subject. The corresponding value is the email subject. Check whether it starts with [Important].
Attachment: you’ll have to look for the email attachments in message[“payload”][“parts”]. The process is a bit more complicated, but see, for example, this related question.
Reference:
Gmail API: Push Notifications

Related

Fetch discord’s message containing specific words

How do i find messageID of the latest message from a specific user containing certain word
i.e
if 2 people sends same message but if i provide 1st person’s userID then it will bypass 2nd users message and get the messageID of 1st users'
I dont know if this is possible haven’t done anything yet!

Site workflow to send reminder email to Created By based on status of the item

I want to create site workflow to send a reminder email to created by(emails) when Item created is more than 30 days and choice field called "Status" is "open". When someone has more than one items with status open in list then that person get one reminder mail only
Thanks in advance
Aside from the issues of maintaining multiple long-running workflows on a site, each item with an open status would need its own workflow so that when it was updated to any other status it could self-terminate.
To resolve prevent duplicate emails, there would need to be an additional list to track which user received a notification email along with the date/time. This list could be queried by a standard rest API call with $select=Id,Modified&$top=1&$orderby=Modified+desc&$filter=<userIdField>%20eq%20<ID> which would provide the most recent record and based on the date determine if an additional email was warranted. If there is no record of an email sent, then a record can be inserted to indicate that "this" workflow instance will send out an email.
It may be important to run this query a second time before the email is delivered to ensure that a race condition did not occur, but if found, the duplicate record with the newer time-stamp will delete its duplicate and self-terminate.

A way to mark notification as seen without reading the notification feed?

My situation is the following:
I'm using the stream-js library. I add entries to the notification feeds of users for certain events - comments, follows, etc. After I write to their feed I also send a push notification to that user's device.
If a user clicks on a push notification I want to be able to mark the corresponding activity as seen. There's currently no way to do that since the add or addToMany calls do not return the ids of the added activities for me to send in the notification payload.
Ideally I'd want a way to mark a notification feed item as seen either by an activity group id or by some other unique id (or the foreignId). Is there a way to do that? If not, what is the alternative?
Two parts to this answer:
Getting the ID of an activity that you just added
The addActivity call in the various Stream client libraries (I'm using stream-js in this case) will return back the created activity, which should include the activity ID. Response looks something like this:
{
actor: 'ken',
duration: '9.65ms',
foreign_id: '',
id: '8b5d69a9-8b73-11e8-98ab-12cb9e7b86a4',
object: 'some-object',
origin: null,
target: '',
time: '2018-07-19T16:48:21.045496',
verb: 'add-activity'
}
Marking notification feed items as seen or read
The way to mark a notification feed item as seen or read is a little funky - first, you get the feed, like you would normally do, but you'll also pass in the mark_seen or mark_read options. (true will mark all items as seen or read, and an array of activity group IDs will mark only those items.)
From that call, the notification feed will be returned without the items marked as seen or read - but the next call to retrieve the notification feed will have the items marked accordingly.
More docs on that here: https://getstream.io/docs/flat_feeds/#notification_feeds
activity ID --> activity group ID
You might have noticed that you get the activity ID when adding the activity, but you need to pass in the activity group ID when marking items seen or read.
All notification feeds are actually aggregated feeds as well - by default, the aggregation format that they use is just the activity ID, which means that there will be only one activity per activity group, and the activity group ID will be the same as the activity ID. So, you can just use the activity ID returned by the addActivity call to get the notification feed and mark that activity group as seen or read.
If you're not using the default aggregation format (e.g., the activity group ID is not the same as the activity ID), then you'll likely have to retrieve the notification feed and grab the necessary activity group ID from there.

When does Message ID get populated in Lotus Notes?

I'm trying to use the Message ID property on a mailbox item to determine whether it's a journaled or non-journaled item.
When I say non-journaled I mean, calendar events, contacts, drafts.
Is this the right thing to do? Is the Message ID assigned when the item is sent?
The Messsage ID is assigned to the $MessageID item by the router when the message is submitted to be sent. A calendar event will not contain a $MessageId, but a calendar invitation or calendar notice will, because they are processed by the mail system.
However, the presence of a $MessageId item does not necessarily mean the message was mailed to or by the specific mailbox that you are looking at, because a message can easily be copied and pasted between mailboxes.
And it's also true that the absence of a $MessageID does not necessarily mean it wasn't mailed, either. I am almost certain that I've seen cases where messages in a user's Sent folder, and which were actually sent, didn't have the $MessageID. I can't recall the circumstances for that, though. (It's pretty easy for a knowledgeable user to remove the $MessageID item from a message by running a simple agent, so that's an obvious reason why you can't count on the $MessageId being there, but that's not the case I'm thinking of.)(

Retrieving Recipient Status via REST API

There appears to be two ways I can gather status information about individual recipients on an envelope:
GET - v2/accounts/:accountId/envelopes/:envelopeId/recipients
GET - v2/accounts/:accountId/envelopes/:envelopeId/audit_events
Unfortunately, each of these suffers from a separate limitation that is making it difficult for me to use either.
This API call returns two DateTime values of interest: deliveredDateTime and signedDateTime. I am able to call and use this API successfully. However, it appears to me that deliveredDateTime is not specified until the user actually clicks the email link AND clicks the review documents button on the signer view. Since what I was actually interested in might be better described as sentDateTime, deliveredDateTime doesn't appear to work for my needs.
This API call returns a detailed list of all events that have transpired on the envelope, including individual receipient status updates. However, the data format is such that in order to tie the result data back to recipients, I have to do string matches on the recipient name. I'd prefer to do the match based on email or, better still, recipientID, but the audit log entries for "sent invitations" and "signed" don't contain these fields. Here is an example (click here to view larger):
Is there an API call other than these two that I can use? Is there a way to get additional data in the audit event API call?
Thank you in advance,
Andrew
I don't believe there's a way to get additional data from the audit_events call since the DocuSign API documentation (which is up to date) indicates that call has no parameters (other than the envelopeId in the URL).
I think you're stuck with doing a string comparison on the userName value to identify/link your recipients, however I want to point out that once you do that you can then link to their unique recipientGuid through the first api call you've highlighted here.
For instance, the /audit_events API call seems to achieve what you want and has all the info you need, however it identifies the recipients through their userNames. If you then make a call on the same envelope and check the response from the /recipients URI, it contains the name, email, recipientId, and recipientGuid for each and every recipient in the envelope. Match the user names and you now have access to their IDs, etc.
So in the end I don't believe there's one API call to achieve this but you can solve by doing one string compare and combining the results from the API calls you've highlighted.

Resources