Reputation: 2663
I am developing a Gmail addon and need to get selected/highlighted text in a Gmail message via Google Apps Script. I can get whole message body via following code, but can't seem to find a way to get selected text.
function onGmailMessage(e) {
// Get the ID of the message the user has open.
var messageId = e.gmail.messageId;
// Get an access token scoped to the current message and use it for GmailApp
// calls.
var accessToken = e.gmail.accessToken;
GmailApp.setCurrentMessageAccessToken(accessToken);
// Get the subject of the email.
var message = GmailApp.getMessageById(messageId);
}
Upvotes: 1
Views: 471
Reputation: 26796
A Gmail Add-on can give you the following event objects when a trigger fires:
A Gmail message resource contains the following information:
{
"id": string,
"threadId": string,
"labelIds": [
string
],
"snippet": string,
"historyId": string,
"internalDate": string,
"payload": {
object (MessagePart)
},
"sizeEstimate": integer,
"raw": string
}
Whereby this information is only available for saved sent / reveived messages or SAVED drafts.
Unfortunately, a Gmail Add-on (unlike a Docs Add-on) does not have any access to the text that is typed / selected client-side into the draft module.
If this feature is crucial for your application you would need to change direction and consider e.g. a Chrome extension where it might be possible to scrape client-side content with HTML / Javascript.
Upvotes: 5