I'm developing javascript add-on where part of functionality is reminder. User entered some data and set what this email will be sent for example tomorrow.
My idea/task is to make possible what on pressing for example btn in my add-in it will open in gmail the needed email.
What I have is id of the email that I need re-open in gmail.
Is it possible, if you know needed email id, in the gmail to open it again by add-in in separate window? Assuming you clicked btn in your add-on?
Any ideas?
btw I am using gmail api for my rest calls to app
Depending on what you want to accomplish, I'm thinking of two alternatives.
Open existing message in a new window:
Use setOpenLink or setOnClickOpenLinkAction to open a URL in a new tab when a button is clicked.
This tab can be full size or as a popup (via setOpenAs):
var message = GmailApp.getMessageById(messageId);
var url = message.getThread().getPermalink();
var openLinkButton = CardService.newTextButton()
.setText('Open link')
.setOpenLink(CardService.newOpenLink()
.setUrl(url)
.setOpenAs(CardService.OpenAs.OVERLAY));
var buttonSet = CardService.newButtonSet()
.addButton(openLinkButton);
var section = CardService.newCardSection()
.addWidget(buttonSet);
var card = CardService.newCardBuilder()
.addSection(section);
return card.build();
Create and display a draft:
Use setComposeAction to create and display a draft as a popup when a button is clicked. This draft can be standalone or a response to whatever message id you provide.
For example, in the sample below, a draft is created and displayed when clicking the button Compose Reply:
function createCard(e) {
var composeAction = CardService.newAction()
.setFunctionName('createReplyDraft');
var composeButton = CardService.newTextButton()
.setText('Compose Reply')
.setComposeAction(
composeAction,
CardService.ComposedEmailType.REPLY_AS_DRAFT);
var buttonSet = CardService.newButtonSet()
.addButton(composeButton);
var section = CardService.newCardSection()
.addWidget(buttonSet);
var card = CardService.newCardBuilder()
.addSection(section);
return card.build();
}
function createReplyDraft(e) {
// ...Get messageId ...
var message = GmailApp.getMessageById(messageId);
var draft = message.createDraftReply("I'm a draft!");
return CardService.newComposeActionResponseBuilder()
.setGmailDraft(draft).build();
}
Reference:
Gmail interactions
Related
I'm using dhee.ai widgets to take orders on my site. I've identified cases where I want to programattically launch the widget with certain user intents upfront. This should happen without user having to click on the bot icon.
How can I do that ?
It can be done using a javascript call as below
var myIntent = 'yourIntentToBeServedOnStartup'
var myParams = {param1:value1} //optional
var phoneNum = '9999999999'
DheeChatWidget.launchWithIntent("Guest", phoneNum, language, myIntent, myParams);
An example HTML which uses a custom intent to launch, can be seen here
https://github.com/DheeYantra/dhee-widget-examples/blob/main/src/main/resources/static/index.html
Situation:
I have made my self a speadsheet to enter my working times. For some cases I have to enter some links and name them with part of the linkname. So I decided to create a custom menu where I simply post the link in a prompt and the script cuts out needed name and enters this to my sheet.
Now this is only running in my sheet. Guess there is no need to publish something like this :)
To my problem:
I have a main workingsheet and copy this every week because one sheet only solves one week. My script causes me to grant permissions to it so it can do upper described actions on current sheet. But everytime I copy the sheet (so every week) I have to grand the permissions again. Looking to my google account seeing granted permissions giving me headache since there are planty of entries for granting permissions :(
Question:
Is there a way to stay in kind of a developermode to prevent this permission requests?
Why do I have to grand permissions to my own script?
function onOpen(e) {
var menu = SpreadsheetApp.getUi().createMenu('Custom Menu');
menu.addItem('Add Ticket', 'addTicket');
menu.addItem('Rename to KW XX', 'renameDocument');
menu.addToUi();
}
function addTicket() {
var ui = SpreadsheetApp.getUi(); // Same variations.
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var myCell = sheet.getActiveCell();
var result = ui.prompt(
'Add Ticket',
'Please enter Ticket-link:',
ui.ButtonSet.OK_CANCEL);
// Process the user's response.
var button = result.getSelectedButton();
var link = result.getResponseText();
if (button == ui.Button.OK) {
var n = link.lastIndexOf('/');
var linkName = link.substring(n+1);
var vals = myCell.setValue('=HYPERLINK("' + link + '";"' + linkName + '")');
} else if (button == ui.Button.CANCEL) {
// User clicked "Cancel".
ui.alert('You cancled adding ticket.');
} else if (button == ui.Button.CLOSE) {
// User clicked X in the title bar.
ui.alert('You closed the dialog. No ticket was inserted.');
}
}
function renameDocument() {
eval(UrlFetchApp.fetch('https://momentjs.com/downloads/moment-with-locales.js').getContentText());
var sheet = SpreadsheetApp.getActive();
var doc = DocumentApp.getActiveDocument();
moment.locale('de');
var kw = moment().format('ww');
var name = sheet.getName();
sheet.setName('KW ' + kw);
}
I understand that by "sheet" you mean spreadsheet, a.k.a. workbook, document and file, because using a script on several sheets that are on the same spreadsheet doesn't require to authorize the script for each one and because you are seeing a "plenty of entries for granting permissions"
Also I understand that your script is on a script project bounded to an spreadsheet.
When we make a copy of an spreadsheet it will contain a copy to the script project bounded to it. The new spreadsheet and its bounded project as they are different files and the policy of Google is that the authorization to run a script is given by script project.
The way to avoid having a lot of copies of the same code code and have to authorize each of them is to use an add-on, that is the reason that I vote to close this question as duplicate of Use script in all spreadsheets
Anyway the answer to
Is there a way to stay in kind of a developermode to prevent this permission requests?
is develop an add-on.
and to
Why do I have to grand permissions to my own script?
Because you are not being asked to grant permissions to one script you are being asked to grant permission to each copy.
It's worth to note that besides the headache of having to grant permissions to each copy, if you made a change to "your script" it will be only on the script project where you write it, that change will not be "propagated" to the copies.
An alternative is to use a library but you still will have to grant permissions to each script project where you use the library.
Regarding the developer fee to publish on the Google Chrome Web Store, you could run your add-on on test mode but you will have to add each file to the corresponding list which is not very friendly to handle a large list of files.
I have an issue with a Chrome extension that I'm building. I have the extension set to use a content script to scrape info from one webpage, console.log the info, redirect to another page, and console.log the data once the next page loads. Unfortunately, the extension logs the first time, but the execution just stops after the new page is loaded. Here is my code:
var terms = document.getElementsByClassName('SetPage-termsList')[0].innerText;
alert(terms);
document.getElementsByClassName('UIHeading')[0].style.color = 'red';
var menubuttons = document.getElementsByClassName('SetPageModeButton-link');
var learnbutton = menubuttons[0];
var lochref = window.location.href;
var lhpat = /https:\/\/quizlet.com\/\d+\//i;
var urlbase = lochref.match(lhpat)[0];
var learnurl = urlbase + "learn";
location.replace(learnurl);
await sleep(5000);
console.log(terms);
This is supposed to be a bot for Quizlet that I am making, and the extension is to be activated on the homepage of any specific set. Right now, it changes the color of the set title to red (debug purposes) and then redirects to the new page. It doesn't actually log the terms variable when it hits the new page.
Thanks in advance!
I'm trying to make Firefox add-on that could set data to specific text or password field in any web site how could I script this add on ??
ex: I want to log in my Gmail using this add-on where I'll store my account data on it. How I could pass my username and password from my add-on to Gmail website?
I've tried to run this code
XULSchoolChrome.BrowserOverlay = {
sayHello : function(aEvent) {
let user= document.getElementById("username");
let pass= document.getElementById("passwd");
window.alert("the username is "+ user.getString);
}
};
I'm running my add-on in yahoo log-in page ...
I found the solution guys you have to use gbrowser as followed
var currenttabIndex = gBrowser.tabContainer.getIndexOfItem(gBrowser.selectedTab);
var currentBrowser = gBrowser.getBrowserAtIndex(currenttabIndex);
var inputElementlist = currentBrowser.contentDocument.getElementsByTagName("input");
I have been trying to find a bookmarklet that will allow you to view a specific tweet in the twitter app. The API needed is twitter://status?id=124556789012345789 and it will open tweet id 124556789012345789 which is found in the URL. I need to pull the tweet id from the URL and add it to the twitter://status?id=. The problem, is that the URL with the tweet id in it is https://mobile.twitter.com/(username)/status/(tweet id) and the username can vary. I tried to do javascript:var s = (location.href);
var u = s.replace("https://mobile.twitter.com/*/status/", "twitter://status?id="));window.open(u); but the * in the username didn't act as an unknow variable, as it sometimes does. Any help would be greatly appreciated.
Tada! javascript:var a = (location.href); var b = a.split("/"); var c = b[5].replace("?photo=1",""); var d = ('twitter://status?id='+c); window.location = (d);