Gmail addon action when user is composing a message - google-apps-script

Is it possible to create an action to trigger a function whenever the user is composing an email?
I am hoping to add an extra button to the UI for composing emails which will insert some text into the email based on the subject and recipients of the email. Looking through the gmail addon docs I can't seem to find a way to do this.
Would this be something better suited as an actual chrome extension instead?

In short : No
For now , you can not add buttons or any other controls inside the Gmail UI. The add on does not do that. And moreover addons cannot listen into GmailUI except for triggering themselves. Thus we cannot know if the user had started typing into the compose window. It is better to create chrome extensions instead, for these kind of tasks.
Note: Gmail addons are at a nascent state. Probably, we might receive these event handlers at a later stage.

Related

Show gmail add on on selecting mails from any label

I am new to write gmail add-ons. Generally Add-ons are shown only when we open 1 thread. My question is: Is there any way to show the add-on on selecting a mail from inbox or any other label, without opening the message thread?
A gmail add-on cannot be triggered when a selection is made through checkbox. But it is a good thought, really. For some reasons , triggering is only possible when you open a thread. However it can also trigger when you switch between messages.

Open Gmail Add-on by default on opening mail

I am working on Gmail Add-on using Google Apps Script.
I wanted to know if there is any way in which my Add-on will be opened by default without clicking on the add-on icon? For example, if the mail contains an attachment, add-on should open without clicking the icon on the sidebar on the right.
As of now, there is no way we can achieve that and that is not possible also because if multiple add ons have similar behaviour on opening mail with attachments, which add on should open. Many race conditions come, so I guess it is not good to have such a feature.

Google Chrome extension - integrate with Google Calendar

How can a Chrome extension alter the Google Calendar event editing UI?
I see that, for example, the Moxtra extension has managed to inject UI including a button just below the location. According to their YouTube video they added a button to fill out the event description although when I installed Moxtra this no longer seems to work.
Stepping back from this a bit, it occurs to me that editing the Google Calendar page seems like something that could easily get messed up by future changes to Google Calendar. Perhaps it is better to edit the event description from the extension's own UI? If so, how can that be done?
Thanks.
It can be done with content scripts and modification of the DOM.
They probably check Event edit page for specific selectors and try to insert their own elements in the page, if they found it.
So, if UI of Google Calendar will change, extensions like Moxtra will be probably also broken.
You are right about the edit of the description - it's safer. But you still need to get a description field and change a content of it. There is no 100% safe way to do it and don't break on the change of UI.

How to apply a Google Apps script to a gmail message from gmail screen

If I have a Google Apps Script that does some processing to a single gmail message, how can I trigger it from the gmail web interface so it gets applied to the message I have currently open on screen?
The closest way I've found is to apply a label and have a background process monitoring labels. Is there a way to add a button or menu option to gmail instead?
Thanks
No, there isn't. At least not using any "native" Apps Script or Gmail feature. You'd have to write a browser extension to achieve this.
Another thing you could do (aside from the special label) is to gmail's URL (while viewing the message) and paste it in your Apps Script interface (previously opened in another tab). Then your script can extract the message id from the URL and work on it right away.
Also, you could do something clever like having your script receive the id (or full gmail url) from a parameter on the script's own url, e.g. https://script.google.com/macros/s/<your-script-key>/exec?gmail=<url>
Then set up your browser (I know Chrome and Firefox do this) to trigger your script and pass the parameter based on a keyword in the location bar. I use mostly just one letter (like "y script" searches the word "script" on youtube. If you use for example "a", you could hit ctrl+L (select location bar), ctrl+c (copies gmail url), ctrl+t (new tab), then type "a ", ctrl+v, enter. Not exactly clicking a button on the gmail's interface, but does the job rather easily. If you're inclined to keyboard shortcuts like I am, this is even a preferable way :)
Another options is to label your message with some label and have an app script scan for this label every X minutes and process all messages it finds.

Creating a notification from within a notification

I'm creating an extension for Chrome, and one of the functionalities included is the ability for the end user to add people as contacts.
Currently, the contact is saved to the database via AJAX, after which a desktop notification is displayed telling the user that the deed has been done.
However, I would want to first ask the user if he's sure he wants to do that. So I got the mad idea of wanting to create a new notification from within a notification.
So first, the confirmation HTML notification would be created from the background.html, and displayed. It contains a button, and upon clicking it, it should run the AJAX function and create a second notification, containing the feedback.
However, I seem to be unable to do this. I can't run createNotification() from the notification, sendRequest() doesn't seem to go through neither, and I can't use the onClose listener from background.html, because I want to differentiate between clicking the "Yes" button and the "No" button.
Is there any way I can do this? And if not, how should the confirmation dialog be implemented instead?
Have you tried using chrome.extension.getBackgroundPage()? This may provide the access to your background page's API that you require. For example, your first notification page calls the following when Yes is clicked;
function yesClicked() {
chrome.extension.getBackgroundPage().showSecondNotification();
}
The background page declares the showSecondNotification method as follows;
function showSecondNotification() {
webkitNotifications.createHTMLNotification(
chrome.extension.getURL('notification2.html')
).show();
}
Hopefully, this will cause the second notification to be displayed. I've used a similar method in my extensions before but only to retrieve information from the background page. However, I see no reason this shouldn't work.