How save setting after next run - office-addins

How do I save settings in a Word add-in so that they're available after next run? I'm creating a task pane add-in with two settings and want to load them automatically every time the add-in runs.

This is how to save settings an your office 365 app in JavaScript:
Office.context.document.settings.set('settings1','100');
This is how to retrieve settings in your o365 app in JavaScript:
write('Current value for mySetting: ' + Office.context.document.settings.get('settings1'));
// Function that writes to a div with id='message' on the page.
function write(message){
document.getElementById('message').innerText += message;
}
Hope this helps.

You can try to follow what is stated in Persisting add-in state and settings TechNet Library. Basically it is allowed to use local add-on storage or in some cases call local web storage or cookie.

Related

Use path/slug after Web App's base url in Google Apps Script

I'm looking to make the url by adding a path which is something like this below in Google Apps Script:
https://script.google.com/macros/s/APP_ID/exec/fileName.txt
How can I achieve this for Web App service?
I believe your goal as follows.
You want to access to Web Apps using the URL of https://script.google.com/macros/s/APP_ID/exec/fileName.txt.
For this, how about this answer? I think that you can achieve your goal using Web Apps. As a sample case, I would like to explain about this using a sample script for downloading a text file, when an user accesses to https://script.google.com/macros/s/APP_ID/exec/fileName.txt.
Usage:
Please do the following flow.
1. Create new project of Google Apps Script.
Sample script of Web Apps is a Google Apps Script. So please create a project of Google Apps Script.
If you want to directly create it, please access to https://script.new/. In this case, if you are not logged in Google, the log in screen is opened. So please log in to Google. By this, the script editor of Google Apps Script is opened.
2. Prepare script.
Please copy and paste the following script (Google Apps Script) to the script editor. This script is for the Web Apps.
function doGet(e) {
const path = e.pathInfo;
if (path == "filename.txt") {
const sampleTextData = "sample";
return ContentService.createTextOutput(sampleTextData).downloadAsFile(path);
}
return ContentService.createTextOutput("Wrong path.");
}
In order to retrieve the value of fileName.txt in https://script.google.com/macros/s/APP_ID/exec/fileName.txt, please use pathInfo.
For example, when you check e of doGet(e) by accessing with https://script.google.com/macros/s/APP_ID/exec/fileName.txt, you can retrieve {"contextPath":"","contentLength":-1,"parameter":{},"parameters":{},"queryString":"","pathInfo":"fileName.txt"}.
In this case, the GET method is used.
3. Deploy Web Apps.
On the script editor, Open a dialog box by "Publish" -> "Deploy as web app".
Select "Me" for "Execute the app as:".
By this, the script is run as the owner.
Select "Anyone, even anonymous" for "Who has access to the app:".
In this case, no access token is required to be request. I think that I recommend this setting for your goal.
Of course, you can also use the access token. At that time, please set this to "Anyone". And please include the scope of https://www.googleapis.com/auth/drive.readonly and https://www.googleapis.com/auth/drive to the access token. These scopes are required to access to Web Apps.
Click "Deploy" button as new "Project version".
Automatically open a dialog box of "Authorization required".
Click "Review Permissions".
Select own account.
Click "Advanced" at "This app isn't verified".
Click "Go to ### project name ###(unsafe)"
Click "Allow" button.
Click "OK".
Copy the URL of Web Apps. It's like https://script.google.com/macros/s/###/exec.
When you modified the Google Apps Script, please redeploy as new version. By this, the modified script is reflected to Web Apps. Please be careful this.
4. Run the function using Web Apps.
Please access to https://script.google.com/macros/s/###/exec/filename.txt using your browser. By this, a text file is downloaded.
Note:
When you modified the script of Web Apps, please redeploy the Web Apps as new version. By this, the latest script is reflected to the Web Apps. Please be careful this.
References:
Web Apps
Taking advantage of Web Apps with Google Apps Script
Updated on February 14, 2023
In the current stage, it seems that pathInfo can be used with the access token. It supposes that the following sample script is used.
function doGet(e) {
return ContentService.createTextOutput(JSON.stringify(e));
}
When you log in to your Google account and you access https://script.google.com/macros/s/###/exec/sample.txt with your browser, {"contextPath":"","parameter":{},"pathInfo":"sample.txt","contentLength":-1,"parameters":{},"queryString":""} can be seen.
In this case, when you access it without logging in Google account, even when Web Apps is deployed as Execute as: Me and Who has access to the app: Anyone, the log in screen is opened. Please be careful about this.
And, if you want to access with https://script.google.com/macros/s/###/exec/sample.txt using a script, please request it by including the access token. The sample curl command is as follows. In this case, the access token can be used as the query parameter. Please include one of the scopes of Drive API in the access token.
curl -L "https://script.google.com/macros/s/###/exec/sample.txt?access_token=###"
By this, the following result is returned.
{"contextPath":"","queryString":"access_token=###"},"pathInfo":"sample.txt","parameters":{"access_token":["###"]},"contentLength":-1}

Microsoft Teams Action messaging extension with task module and URL not working

I am trying to build an action messaging extension with a task module implementation which uses a URL attribute to load the page. Attached is the screenshot of the task module code which was generated by Yeoman Teams generator.
The popup comes up blank. So it means it's not loading the HTML file path, but if I open Chrome and try to load the URL, it works fine.
Also instead of using URL if I use an adaptive card it works fine. Only the URL part doesn't load on the popup. Attached is another screenshot of the popup inside teams:
What could be wrong with the code?
The other answer is correct in that your url needs to be reflected 100% correctly in your manifest. However, there are a few things that you need to be clear on:
It's not per se the address of the BOT that's important, but rather the address of the web page itself that needs to be listed in your safe domains list in your manifest. In your case, they're hosted in the same endpoint, but they might not be in your final solution, depending on how you end up hosting this.
While you're developing locally, rather use App Studio. That way, you don't need to fiddle with the zip file every time - you can just change it in App Studio and immediately redeploy with the updated URL
Every time when you compile and run the project, a new hostname is generated since ngrok free license is used in the yo teams scaffolding, which makes the app to reference to the old URL.
You need to uninstall the app from the Teams app store under your organization and upload the new app from the package folder .zip (Only after gulp ngrok-serve)
If it still does not work, check the below
Unzip the package file and verify the manifest whether it's pointing to the right hostname of the action html page
Go to http://localhost:4040 to inspect the ngrok tunnel traffic that should give more info on the routed requests.

AWS IoT Subdomain Too Long for AWS IoT Button (Gen 1)

I'm trying to connect a generation 1 AWS IoT Button (the blue kind) to my AWS IoT core instance.
In the configuration, it says to input a subdomain that is 14 characters long so that it can create the endpoint for the button. However, my IoT endpoint is 18 characters long - it has an additional -ats at the end of it.
So, while my endpoint is actually
XXXXXXXXXXXXXX-ats.iot.us-west-2.amazonaws.com
It won't let me add the -ats at the end of it. So I'm stuck with
XXXXXXXXXXXXXX.iot.us-west-2.amazonaws.com.
Is there a way to input the full AWS IoT endpoint? Or is the -ats ending not needed and it's another issue with connecting the button to a network?
I had a similar problem trying to manually setup the AWS button.
As an alternative to using the tutorial to configure the button manually, I used the AWS IoT Button Dev application on an iphone. Using the iPhone app worked.
Apple App Store
Google Play Store
The resulting url in the console still contained the -ats suffix in the endpoint. I do not know if the app is bypassing the 14 character limitation, or if it is not needed, but this at least got me up and running with the button. If that is your goal, this should get you going.
You can also edit the html on the form in the developer console. The maxlength on the input element named "subdomain" is set to 14. Change that to >=18 and you should be able to submit the form.

Accessing Local Settings in Windows 10

I am developing a Line-of-Business app for a client. The client specified the devices that were supposed to be used (some Dell tablet with Windows 8.1). Now, that the development is almost done and we were ready to release the first phase of the application, the client informed us that they have changed their mind and all those Dell tablets will run windows 10. I upgraded one tablet that I used for development and testing to Windows 10 as well. The tablet uses a RESTful Web API to access data stored in a repository. Obviously, the URL of the Web API must be configured in the settings of the app before the app can retrieve any data from the repository.
So I create the App Package to sideload the app on the tablet. The installation works properly, the app starts well for the first time. I go into the settings, set the URL and close the app.
When I try to restart, the app gets stuck showing the Splash Screen. If I try to access the Settings, I am informed that the settings for my app are not available at that time. The only way to get out of this is to uninstall the app and reinstall it again.
This is the code I use to save and retrieve the settings:
public void SaveSetting<T>(string settingName, T value)
{
ApplicationData.Current.LocalSettings.Values[settingName] = value;
}
public T GetSetting<T>(string settingName)
{
var localSettings = ApplicationData.Current.LocalSettings.Values;
if (localSettings.ContainsKey(settingName))
{
var value = localSettings[settingName];
if (value is T)
{
return (T)value;
}
}
// else, in all other cases
return default(T);
}
An interesting thing I noticed is that sometimes, depending on what I try to save in the settings, the app starts. For example, I was playing with it and tried to save some garbage instead of the correct URL. So instead of "http://x.x.x.x:nnnnn" I saved "a". The app started correctly, I got past the splash screen but obviously, I couldn't get any data.
Any ideas as to what exactly is happening? Did the access method for local settings change in Windows 10?
I have been scratching my head over this for the past couple of days. Initially, I thought it is a matter of permissions to create the Local Settings file, so I dedicated a lot of energy trying to find a solution from that perspective. However, as I said, if I dump some garbage in the settings, it works, so it's not a matter of permissions. Could it be that and IP address like "x.x.x.x" needs to be saved in a different way than as a string?
Any advice would be highly appreciated.
TIA,
Eddie
After I added some logging to my application I was able to prove that the app had no issues reading the settings. It's what it tried to do with them that it did not work. The URL read from the settings was correct but when the app tried to make calls to the Web API, the calls threw an exception and the app stopped working. So this shouldn't have been a question in the first place.
Thanks, Eddie

Disable Session.checkAgent for one action

I have built a controller that is uses the media view to stream videos to users. When someone accesses the controller from an iOS device, the user agent being sent is not matching and the session logs out.
I am using the iPad plugin for Flow Player and I have seen other posts about flash not sending the correct user agent strings, so instead of messing with that, I'd like to disable Session.checkAgent for that specific action. I have tried adding it to beforeFilter(), but the check clearly happens before that point.
Is there some other method I can override to implement this?
I haven't tested it, but if you know (part of) the URL, you can check the $_GET['url'] inside your app/Config/core.php and modify the session configuration based upon its value, For example, $_GET['url'] starts with '/videos/view'.
You need to do this inside the configuration file, otherwise the session is already started as you already discovered.
Note that $_GET['url'] is only used in older versions of CakePHP. For newer versions of CakePHP, you may need to user $_SERVER['REQUEST_URI'] or another $_SERVER environment variable.

Resources