Usage for displayNewMessageForm with unsaved attachments possible? - outlook-addin

We are working on an Office AddIn for Outlook and we need to open a new message with predefined data we are getting from our own rest-interface in Json format like this:
{
"attachmentNo": "1",
"Content-Type": "application/pdf;",
"name": "CPV - Lohnbeilage Planwahl_2018_Lohnbeilage_D.PDF",
"Content-Transfer-Encoding": "base64",
"Content-Disposition": "attachment;",
"filename": "CPV - Lohnbeilage Planwahl_2018_Lohnbeilage_D.PDF",
"content": "JVBERi0xLjUNCiW1tbW1DQoxID....",
"fileType": "pdf",
"fileSize":"15MB"
}
To provide an attachment for the displayNewMessageForm Method I need the format:
{
type: 'file',
name: "CPV - Lohnbeilage Planwahl_2018_Lohnbeilage_D.PDF",
url: ???,
isInline: false
}
Is there any possibility to use something like a data-url like this:
'data:application/octet-stream;charset=utf-8;base64,JVBERi0xLjUNCiW1tbW1DQoxID....'
as url or is there another trick how I can manage to add an unsaved attachment to the new message?

Currently there is no way to pass base64 attachments as part of the displayNewMessageForm API. We track Outlook add-in feature requests on our user-voice page. Please add your request there. Feature requests on user-voice are considered when we go through our planning process.
Meanwhile we do have an API that lets you add base64 attachments to the current Item (documentation). What you can do is the following: once the new form opens, open the add-in, call into this API to add the attachment. Note that this API is in preview (prone to changes) and currently only available in Outlook Desktop for build numbers > 16.0.10730.1000.

Related

Is there a way in the Google Sheets API to access the script editor?

For example, I'd like to write a (Python, say) program that generates a Google sheet, then writes some custom .gs code into the Apps Script attached to that sheet, then writes values into the sheet itself using formulas defined in the Apps Script. What I currently do is use Tools > Script Editor, then manually copy-paste the relevant Apps Script code.
As mentioned by #Tanaike, You can use Apps Script API to add container-bound script.
(OPTION 1: Writing the function manually in the script content)
What to do:
Create a container-bound script using projecs.create method.
To set a container-bound script, you need to assign the spreadsheet file id to the parentId parameter
Sample Request Body:
{
"title": "new",
"parentId": "spreadsheet file id"
}
Get the newly created container-bound script id in the project response body of projecs.create method.
Sample Response Body:
{
"scriptId": "newly created script id",
"title": "new",
"parentId": "spreadsheet file id",
"createTime": "2020-12-25T23:33:48.026Z",
"updateTime": "2020-12-25T23:33:48.026Z"
}
Update the content of the newly created bound script using projects.updateContent method and include your function.
Sample Request Body:
{
files: [{
name: 'hello',
type: 'SERVER_JS',
source: 'function helloWorld() {\n console.log("Hello, world!");\n}'
}, {
name: 'appsscript',
type: 'JSON',
source: "{\"timeZone\":\"America/New_York\",\"" +
"exceptionLogging\":\"CLOUD\"}"
}]
}
(OPTION 2: Copy an existing script and paste it as bound script)
Create a standalone script that will contain your custom functions.
Get the newly created standalone script project content using projects.getContent which will return a content resource
scriptId can be seen in your standalone script project under File -> Project Properties
Create a container-bound script using projecs.create method.
To set a container-bound script, you need to assign the spreadsheet file id to the parentId parameter
Sample Request Body:
{
"title": "new",
"parentId": "spreadsheet file id"
}
Get the newly created container-bound script id in the project response body of projecs.create method.
Sample Response Body:
{
"scriptId": "newly created script id",
"title": "new",
"parentId": "spreadsheet file id",
"createTime": "2020-12-25T23:33:48.026Z",
"updateTime": "2020-12-25T23:33:48.026Z"
}
Update the content of the newly created bound script using projects.updateContent method.
Use the content resource returned in Step 2 as the request body. Make sure to replace the script id based on the newly created bound script id that is obtained in Step 4.
Example Standalone Script:
Example Result of the Workaround:
You can now use the custom function in the Google Sheets

How to keep both button text and payload in whatsapp quick reply message template

Whatsapp quick reply request template has option for payload only. In what option we can configure the button text. After lots of searching on internet I did not find proper solution.
Here is the json of button which need to be send in request but it only has the payload option
{
"type": "button",
"sub_type" : "quick_reply",
"index": "0",
"parameters": [
{
"type": "payload",
# Business Developer-defined payload
"payload":"aGlzIHRoaXMgaXMgY29vZHNhc2phZHdpcXdlMGZoIGFTIEZISUQgV1FEV0RT"
}
]
},
Reference link: https://developers.facebook.com/docs/whatsapp/api/messages/message-templates/interactive-message-templates#request
You need to configure that in the Facebook Business Manager UI or in the Graph API post request when you create the template. When you're sending the message, you can't dynamically configure the text.

How to retrieve callback token for sending emails for API set v1.3

Scenario:
Permission on the Manifest: ReadWriteMailbox
We have a outlook add-in that has a button that sends email from the compose mode of OWA/Outlook Desktop add-in. We are doing that by
Get the callback token.
Get item rest id.
Get rest url (which turns out to be https://outlook.office365.com/api).
Making a POST call to https://resturl/v2.0/me/messages/restId/send
dataType: 'json',
Headers
'Authorization': 'Bearer callbackToken'
Problem:
The email sends successfully in OWA (Outlook Web) but on Outlook 2016 Desktop we get an 403 Forbidden response with
code: ErrorAccessDenied
message: The api you are trying to access does not support item scoped OAuth.
Our Analysis
As far as we have investigated, Outlook 2016 MSI install does not support v1.5 of API requirement set
see this:
API requirement set
Since, there are two getCallbackTokenAsync methods as per
https://dev.office.com/reference/add-ins/outlook/1.5/Office.context.mailbox?product=outlook&version=v1.5
we are using the one with the isRest option set to true, i.e. the v1.5 one
Our code to get the callback token:
Office.context.mailbox.getCallbackTokenAsync({
isRest: true
},
function(asyncResult) {
if (asyncResult.status === "succeeded") {
deferred.resolve(asyncResult.value);
} else {
deferred.reject("Could not retrieve token");
}
});
Code to get rest id
function _getItemRestId() {
// Currently the only Outlook Mobile version that supports add-ins
// is Outlook for iOS.
if (Office.context.mailbox.diagnostics.hostName === 'OutlookIOS') {
// itemId is already REST-formatted
return Office.context.mailbox.item.itemId || pvt.currentMailId;
} else {
// Convert to an item ID for API v2.0
return Office.context.mailbox.convertToRestId(Office.context.mailbox.item.itemId || pvt.currentMailId, Office.MailboxEnums.RestVersion.v2_0);
}
}
Code to get the rest url
function _getRestUrl() {
$timeout(function() {
notificationService.showInfo('This is the rest URL==> ' + Office.context.mailbox.restUrl);
});
console.log('Office REST URL =>', Office.context.mailbox.restUrl);
return Office.context.mailbox.restUrl || 'https://outlook.office.com/api'; // This is because this requires v1.5 api set requirements which is not yet supported in Outlook for Windows.
}
Most Probably,
the getCallbackTokenAsync that executes on Outlook Desktop is that of v1.3 API set and gets us some different token (for getting attachments for an item i guess.) although I am not 100% sure that this is exactly what is wrong with our app.
Will be grateful if I can get a fix to send emails using API v1.4 requirement set.
There is nothing on other forums regarding this and also on the official documentation for that matter.

How to pass a file to an API from Azure Logic App

I have a simple Logic App. The trigger is on New file (ex: Dropbox, OneNote, etc.)
I want to pass the filename and the fileContent to a API APP (web Api).
But I got error, or worse the content is null once in the API!
The API is in C#.
How do you pass a file (ex: pdf, png) to and API from Logic App
UPDATE:
In Logic App here my action code:
"UploadNewFile": {
"inputs": {
"method": "post",
"queries": {
"filedata": {
"fileName":"#triggerOutputs()['headers']['x-ms-file-name']",
"fileContent":"#base64(triggerBody())"
}
},
"uri": "https://smartuseconnapiapp.azurewebsites.net/api/UploadNewFile"
},
"metadata": {
"apiDefinitionUrl": "https://smartuseconnapiapp.azurewebsites.net/swagger/docs/v1",
"swaggerSource": "website"
},
"runAfter": {},
"type": "Http"
}
In my API App, If the function is declared like this filedata is null
[Route("api/UploadNewFile")]
[HttpPost]
public HttpStatusCode UploadNewFile([FromBody] string filedata)
And if I don't add the [FromBody] like that I got an error.
[Route("api/UploadNewFile")]
[HttpPost]
public HttpStatusCode UploadNewFile(string filedata)
Yes you can send binary content to your own API in a few different methods. Our out-of-the-box actions use this as well.
If you want to send the binary contents as the request body
For example, an outgoing request from the Logic App could have binary content and a content-type header of image/png
In this case the swagger for the body of your request should be binary - or:
{ "name": "body",
"In": "body",
"Schema": {
"Type":"string",
"Format": "binary"
} ... }
That should tell the designer that the request body is binary content. If a previous action or the trigger had binary data (e.g. "When a file is added to FTP") and you used that output in the body, it would show up in your custom API inputs as:
"Body": "#triggerBody()"
Notice there are no { and } on the expression (string interpolations) which would convert the binary content to a string. This would send an outgoing request to the connector with the binary content - so your controller just needs to accept binary content and honor the content-type header as needed.
If you want to send binary content in a JSON request
Sometimes you don't want to send binary as the full request, but as a property of another object. For instance a person object may have a name, address, and profile pic all in the request body. In this case we recommend sending the binary content as base64 encdoded. You can use "format": "base64" in swagger to describe a property as this. In code-view would look something like:
"Body": {
"Name": "#triggerBody()['Name']",
"ProfilePic": "#base64(body('Dropbox'))"
}
Hope that helps. Let me know if you have any questions - here is an article on how logic apps preserves content-types as well.
I found how to to it.
I needed to pass the filename in the querystring and the file in the body of the HTTP Request. Today, it's not possible to do it using the design view so you need to go in code view.
In the Logic App code
"queries": {
"fileName": "#{triggerOutputs()['headers']['x-ms-file-name']}"
},
"body": "#triggerBody()"
In the API App code
public HttpResponseMessage UploadNewFile([FromUri] string fileName)
{
var filebytes = Request.Content.ReadAsByteArrayAsync();
[...]
}
A more detailed explanation can be found in this blog post:
http://www.frankysnotes.com/2017/03/passing-file-from-azure-logic-app-to.html

Is it possible to post files to Slack using the incoming Webhook?

I am trying out the Slack's API using the incoming webhook feature, posting messages works flawlessly, but it doesn't seem to allow any file attachments.
Looking through I understand I have to use a completely different OAuth based API, but creating more tokens just for the purpose of uploading a file seems odd when posting messages works well, is there no way to upload files to slack with the incoming webook?
No, its is not possible to upload files through an incoming Webhook. But you can attach image URLs to your attachments with the image_url tag.
To upload files you need to use the Slack Web API and the files.upload method. Yes, it requires a different authentication, but its not that complicated if you just use a test token for all API calls.
You can see in the Slack API document that it's easy to add an attachment to the POST message to your webhook. Here is a simple example of sending a text message with an attachment in NodeJS:
import fetch from "node-fetch";
const webhook_url = "https://hooks.slack.com/services/xxxx/xxxx/xxxxxxxx"
const url = "https://1.bp.blogspot.com/-ld1w-xCN0nA/UDB2HIY55WI/AAAAAAAAPdA/ho23L6J3TBA/s1600/Cute+Kitten+13.jpg"
await fetch(webhook_url, {
method: "POST",
body: JSON.stringify({
type: "mrkdwn",
text: "Example text",
attachments: [
{
title_link: url,
text: "Your document: <file name>"
},
],
}),
headers: {
"Content-Type": "application/json",
Accept: "application/json",
},
});