Presending event + using promise to fetch data

479 views
Skip to first unread message

Maximilian Paju

unread,
Nov 29, 2016, 12:03:28 PM11/29/16
to InboxSDK
Hi,

I want to do goo.gl URL shortener on links in my email message body before sending the email. BUT I want to do this last of all. So I want to do that API call on the presending event fire - is this possible? If the call is slow then the data won't return before the mail is already sent...

Does anyone have a solution to this issue? 

/M

Omar Ismail

unread,
Dec 1, 2016, 12:52:15 AM12/1/16
to Maximilian Paju, InboxSDK
Right now you can't delay the send event. You can cancel it though. So one thing you may be able to do is cancel the send event then hide the compose window, do your API calls, modify the body, and then send the compose programmatically with composeView.send()

--
You received this message because you are subscribed to the Google Groups "InboxSDK" group.
To unsubscribe from this group and stop receiving emails from it, send an email to inboxsdk+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/inboxsdk/332fb50a-8ccf-4a58-be32-0446bcd33da6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Maximilian Paju

unread,
Dec 2, 2016, 7:44:35 AM12/2/16
to InboxSDK, maximil...@gmail.com
That's a great idea! Thanks Omar :)


On Thursday, December 1, 2016 at 6:52:15 AM UTC+1, Omar Ismail wrote:
Right now you can't delay the send event. You can cancel it though. So one thing you may be able to do is cancel the send event then hide the compose window, do your API calls, modify the body, and then send the compose programmatically with composeView.send()
On Tue, Nov 29, 2016 at 9:03 AM, Maximilian Paju <maximil...@gmail.com> wrote:
Hi,

I want to do goo.gl URL shortener on links in my email message body before sending the email. BUT I want to do this last of all. So I want to do that API call on the presending event fire - is this possible? If the call is slow then the data won't return before the mail is already sent...

Does anyone have a solution to this issue? 

/M

--
You received this message because you are subscribed to the Google Groups "InboxSDK" group.
To unsubscribe from this group and stop receiving emails from it, send an email to inboxsdk+u...@googlegroups.com.

Michael Hosford

unread,
Feb 23, 2017, 2:56:19 PM2/23/17
to InboxSDK, maximil...@gmail.com
Hi Omar,
After reading your suggestion, I tried a variation of your solution:
  1. Listen for "presending" event
  2. Cancel the send event
  3. Close the ComposeView
  4. Work my magic on the draft and send it from background page, via Gmail API
    • users.drafts.get
    • make changes to body
    • users.drafts.update
    • users.drafts.send
It works fine, except that occasionally I end up with an empty message body.  I have a hunch that this happens when I quickly type a message body (e.g., "alskhflashfasl") and hit send, and maybe the message isn't saved yet.  I'm guessing that if you use ComposeView.send(), it makes sure all the fields have been saved before sending.  Does InboxSDK provide a way for me to be sure all fields have been saved before I hand it off to my background page for processing?  Or if not, can you suggest another way?

I searched through the InboxAPI docs, looking for some (perhaps Promise-ish) way to determine "saved-ness", but didn't find anything that looked like the answer.

Thanks,
Michael


On Thursday, December 1, 2016 at 12:52:15 AM UTC-5, Omar Ismail wrote:
Right now you can't delay the send event. You can cancel it though. So one thing you may be able to do is cancel the send event then hide the compose window, do your API calls, modify the body, and then send the compose programmatically with composeView.send()
On Tue, Nov 29, 2016 at 9:03 AM, Maximilian Paju <maximil...@gmail.com> wrote:
Hi,

I want to do goo.gl URL shortener on links in my email message body before sending the email. BUT I want to do this last of all. So I want to do that API call on the presending event fire - is this possible? If the call is slow then the data won't return before the mail is already sent...

Does anyone have a solution to this issue? 

/M

--
You received this message because you are subscribed to the Google Groups "InboxSDK" group.
To unsubscribe from this group and stop receiving emails from it, send an email to inboxsdk+u...@googlegroups.com.

er...@streak.com

unread,
Apr 14, 2017, 7:47:26 PM4/14/17
to InboxSDK, maximil...@gmail.com
Hi Michael!

It seems totally plausible that Gmail hasn't updated the draft with it's body contents by the time you make your Gmail API request. Unfortunately at the moment we have no API that really satisfies that need — the 'destroy' event is fired as soon as the ComposeView's DOM element is removed so even that won't help. We don't typically recommend taking over email sending via the Gmail API, simply because it can be a slightly unexpected/unreliable experience — i.e. if your Gmail API code fails for whatever reason, your users may think their email has been sent when really it hasn't, or they may see their 'sent' message in the Drafts folder if they navigate to Drafts before your Gmail API code has finished, etc. Obviously if your use case is important enough that you are willing to take on that risk then the reward may be worth it.

To answer your question re: the ComposeView.send() function saving all changes before sending: you are correct that calling .send() would avoid an out-of-date message. Behind the scenes .send() just delegates to Gmail's native send, so the behavior is precisely the same as if the user themselves clicked the send button. The one downside of using .send() for this case is that you'd either have to visually hide the ComposeView or leave it open and visible while you do your async work (whether they are API calls or something else), then modify the body, then call .send(). Since InboxSDK doesn't currently have a good way to programmatically hide the ComposeView without closing it, you'd probably have to write your own DOM manipulation code, which could be annoying and prone to periodic breakage.

How long does the async operation you're performing take before you modify the email body? If it is a consistently fast operation (which probably rules out any network/API calls), you could probably get away with just keeping the ComposeView open and visible while you do the work.

Lou Wynn

unread,
Oct 4, 2017, 3:13:19 AM10/4/17
to InboxSDK
Hi InboxSDK Guru,

I'm having a similar situation. Is there some pieces of code that show (1) canceling sending, (2) minimizing the ComposeView, (3) changing the body of the message, and (4) call the send() function? I kind of know which function to do individual steps, e.g., event.cancel() does step (1) in the presending handler, but I'm little confused where to place other code. My hunch is that I should not place them all in the handler, but where to place them especially for (3) and (4).

Thanks very much,
Lou

Lou Wynn

unread,
Oct 4, 2017, 3:53:59 PM10/4/17
to InboxSDK
Reply all
Reply to author
Forward
0 new messages