Using PowerApps AzureServiceBus connector SendMessage ContentData - azure-blob-storage

The PowerApps - Azure Service Bus Connector function that I am trying to use is defined as:
ServiceBus.SendMessage(EntityName:Text, {systemProperties :Text, ContentData:Blob, ContentType:Text, Properties:Table, MessageId:Text, To:Text, ReplyTo:Text, ReplyToSesionId:Text, Label:Text, ScheduledEnquequeTimeUtc:DateTime, SessionId:Text, CorrelationId:Text, SequenceNumber:Number, LockToken:Text, TimeToLive:Text})
As you can see ContentData is of type Blob, and PowerApps seems unable to convert a text string to a blob. So although the below will send a message, the content is empty on inspection in either the service bus explorer or a receiving application. Note that the Properties table data and Label value can be seen in the received message.
ServiceBus.SendMessage("TestTopic",{ContentData:"HelloWorld", Label:"MyLabel", Properties:Table({key:"MyUserDefinedKey",value:"MyUserDefinedKeyValue"})})
Is there anyway to directly populate the ContentData with text? I was hoping to use a PowerApp text input.
I have tried changing the ContentType and ContentData to various options without success.

From what I can tell in the docs, the data type for ContentData is bytes which I don't believe PowerApps supports (find supported data types here).
One thing to try would be: ContentData: JSON("Hello World", JSONFormat.IncludeBinaryData)
This is the only way I know of to handle binary data in PowerApps but I'm unsure if it will encode text.

You can send custom properties in a Power Apps Service Bus connector SendMessage call using the Properties parameter. The Properties parameter takes a Table with specific rows of key and value pairs.
I didn't find the ContentData parameter well documented. In my testing it takes a data URI string value with mandatory base64 encoding. Unfortunately there is no built in way to base64 encode in a canvas Power App. If the parameter value isn't properly formatted the resulting Servivce Bus queue message will have an empty ContentData value. Below is an example that sends a new message to the queue, setting the broker property: Label, and three custom properties, along with the text "Hello world!" in the ContentData parameter.
Example:
ServiceBus.SendMessage("p1imagecaptureevents",
{ContentType:"text/plain"
,Properties:Table (
{key: "Label", value: "labelvalue2"},
{key: "myFirstFieldName", value: "'My first field's value8'"},
{key: "mySecondFieldName", value: "My second field's value5"},
{key: "myOtherFieldName", value: "More values5"})
,ContentData:"data:text/plain;base64,SGVsbG8gd29ybGQh" // "Hello world!" base64 encoded text
})

Related

Is there a way that we can maintain a json in FHIR?

I wanted to store a JSON in FHIR. JSON can be anything, for example, it can be something like
{
assignee: "PCC OFF SHORE",
dueby: "30-03-1991",
description: "This will be assigned to PCC off shoure"
}
You can store any arbitrary data as a Binary resource in an Attachment data type (e.g. DocumentReference or in an extension). Technically, you could also put it in a string data type, but that wouldn't be terribly appropriate as strings are not expected to be parseable.
Certain FHIR resources accept elements of type value[x]. That type accepts variations like valueString or valueCode. For your case, valueBase64Binary may be a good alternative.
Read: https://www.hl7.org/fhir/extensibility.html#extension

Attach meta data / custom data to slack messages sent through the API

I am developing a series of Slack apps for my workspace, and some of them are meant to interact with the content (messages) delivered by the other apps : extracting content IDs that may be referred to by other messages
A concrete example :
Suppose I have an app A "FindUser" that is capable of giving me the user profile when a slack user types find me#example.com, and it replies in the thread with a formatted view of the user profile
I am developing an app B "EditTags", which basically gives me a right click option with "edit tags" (see Slack's Interactive Components/Actions), the idea being that a user could first ask app A to find a user, and then right click on the reply from App A and click the "edit tags" action given by the other app. What this app B does it actually retrieve the tags for the user mentionned by the previous message from app A, and in another reply to the thread it gives some controls to either delete an existing tag OR it shows a select with autocomplete to add new tags.
The B app needs to retrieve the user ID that the A app mentionned previously. So I need some way to pass that data directly in the slack message. When looking at the examples, slack does not seem to provide a way to add arbitrary "metadata" to a message, am I wrong ? Do you have workaround for this ? I mean I could totally send the user ID say, in the footer, so I can just read the footer, but I was planning to use the footer for something else... Is there a way to pass metadata hrough properties that would be hidden to the end user ?
Although this does not feel relevant, I am building a slack nodeJS app using the node slack sdk (and especially the #slack/interactive-messages package)
For the most part the Slack API does not provide any official means to attach custom data / meta data to messages. But with some simple "hacks" it is still possible. Here is how:
Approach
The basic approach is to use an existing field of the message as container for your data. Obviously you want to pick a field that is not directly linked to Slack functionality.
Some field are not always needed, so you can just use that field as data container. Or if its needed, you can include the functional value of that field along with your custom data in the data container.
For example for message buttons you could use the value field of a button and structure your code in a way that you do not need it in its original function. Usually its sufficient to know which button the user client (via the name field), so the value field is free to be used for your custom data. Or you can include the functional value of your button along with the custom data in a data container (e.g. a JSON string) in that field.
Serialization
All messages are transported through HTTP and mostly encoded as UTF-8 in JSON. So you want to serialize / de-serialize your data accordingly, especially if its binary data. If possible I would recommend to use JSON.
Length
The maximum allowed length of most fields is documented in the official Slack API documentation. e.g. for the value field for message buttons can contain up to 2.000 characters. Keep in mind that you need to consider the length of your data after serialization. e.g. if you convert binary data into Base64 so it can be transported with HTTP you will end up with about 1.33 characters for every byte.
Contents
In general I would recommend to keep your data container as small as possible and not include the actual data, but only IDs. Here are two common approaches:
Include IDs of your data objects and load the actual objects
from a data store when the request is later processed.
Include the ID of server session and when processing the request you
can restore the corresponding server session which contains all data
objects.
In addition you might need to include functional values so that the functionality of the field you are using still works (e.g. value of a menu option, see below)
Implementation
Dialogs
Dialogs provide an official field for custom data called state. Up to 3.000 characters.
Message buttons
For Message buttons you can use the message action fields / value. Up to 2.000 characters. Its also possible to use the name field, but I would advise against it, because the maximum allowed length of that field is not documented.
Message menus
For Message menus you can use the value field of an option or the name field of the menu action.
Usually the value field is the better approach, since you have a documented max length of 2.000 and it gives you more flexibility. However, you will need to combine you custom data with the actual functional value for each option. Also, this will not work for dynamic select elements (like users), where you can not control the value field.
When using the name field note, keep in mind that the maximum allowed length of name is not documented, so you want to keep you data as short as possible. Also, if you want to use more than one menu per attachment you need to include the actual name of the menu into your data container.
Normal message attachments
Normal message attachments do not contain any suitable field to be used as container for custom data, since all fields are linked to Slack functionality.
Technically you could use the fallback field, but only if you are 100% sure that your app is never used on a client that can not display attachments. Otherwise your data will be displayed to the user.

Apache Nifi: How to convert string (text/plain) to JSON type using Nifi processor?

Please guide me the right component for converting string to json
using appropriate Nifi processor component.
Input is a string of content type text/plain
{ productName : "tv", locationName: " chennai"}
Output of EvaluateJsonPath is still the same as I am unable to evaluate json property based on json path due to wrong content type sent as input.
{
productName : "tv",
locationName: " chennai"
}
Note: Tried SplitText, AttirtubesToJson processors not able to achieve desired conversion.
This is because the input data is not valid JSON. I recreated this flow locally and the error from EvaluateJsonPath is
2017-08-22 10:20:21,079 ERROR [Timer-Driven Process Thread-5] o.a.n.p.standard.EvaluateJsonPath EvaluateJsonPath[id=0aec27af-015e-1000-fac5-4e0f455a10fe] FlowFile StandardFlowFileRecord[uuid=b903eeb0-8985-4517-910f-5e3bbbccb8dc,claim=StandardContentClaim [resourceClaim=StandardResourceClaim[id=1503421928125-1, container=default, section=1], offset=376, length=47],offset=0,name=91708717370829,size=47] did not have valid JSON content.
Which condenses to [flowfile] did not have valid JSON content. The processor uses a strict validator and the input you're providing is not valid JSON. You'll need to use text manipulation or regexes to update this content to the following:
{"productName":"tv", "locationName":"chennai"}
Once you have accomplished this (via ReplaceText, etc.), the EvaluateJsonPath processor will work properly.
Also, to be clear, EvaluateJsonPath is designed to execute JSONPath expressions to extract JSON values to flowfile attributes. It is not designed to manipulate arbitrary text into JSON format.
Update
There is no universal process to convert arbitrary data to JSON. Given the specific input you provided, the following values for ReplaceText will convert this to valid JSON:
Search Value: (?<!\")(\w+)(?=[\s:])
Replacement Value: "$1"
Replacement Strategy: Regex Replace
Evaluation Mode: Entire text
If you get incoming data that is invalid in some other way, you'll have to modify this process. You may be interested in something like JSONLint to validate and format your incoming data.

Kendo Grid - oData - Web API- Server Side Paging, Filtering - Decimal Type

I have set up the kendo grid with the following:
ASP.NET Web API with oDataController to read data using the oData formats.
Kendo grid with oData datasource with server side paging, filtering and sorting.
Everything works fine as expected except the filtering is not quite working with a column of decimal type. When using filtering on decimal type column, the kendo generates URL with the following filter value:
$filter=Value gt 0.5
The Web API returns Bad Request with the following:
{
"odata.error":{
"code":"","message":{
"lang":"en-US","value":"A binary operator with incompatible types was detected. Found operand types 'Edm.Decimal' and 'Edm.Double' for operator kind 'GreaterThan'."
}
}
}
If I take the URL and add 'M' at the end of 0.5 to explicitly specify type of decimal then it is working fine. Apparently when using Web API oData filtering, for some types such as decimal, double, datetime, you have to explicitly specify type in the URL as per this article: http://microliteorm.wordpress.com/2013/09/06/webapi-odata-filtering/
In terms of specifying column types in grid, there is only one type for numeric which is "number". It doesn't have different types for double, decimal, integer etc. How can I tell Kendo grid to specify the actual type (i.e. double, decimal etc.) in the URL when using filtering on "number" columns. Please note the filtering is working for datetime type. It's only an issue with numeric types.
EDIT:
Found this article (Section No 6) on oData which specifies how primitive data types must be represented in URI - http://www.odata.org/documentation/odata-version-2-0/overview/
Kendo UI does not support specific numeric data types like int, float, or decimal. In this framework, and JavaScript, all of these are simply numbers. Kendo provides number as a type abstraction that's useful for your understanding, not the browser's or server's interpreter.
As Jeremy hinted in his comment, you would have to replace the value of 0.5 with 0.5m before sending it to the server. The Kendo UI DataSource provides just the method to do this.
var ds = new kendo.data.DataSource({
transport: {
//...other implementation details removed for brevity
parameterMap: function(data, type) {
if (type === 'read') {
//...covert decimal values in the `data.filter` to strings ending with 'm'
}
}
}
});
Rather than converting the data stream coming in, I feel, it might be more eficient and convenient to convert that filter, which will be a conversion for a unique item, once when it needs to be converted.
For this, look into your ODATA wrapper, where it queries the source. It should have a state property which is passed in as argument, and that state property has a filter property, which itself is a tree of FilterDescriptor objects. You would want to manipulate these, rather than all your data.

Parse, Add option to User in Data Browser

I wanted to create a new option in the Data Browser (just like the "username", "password", "authData"...fields), to hold a monetary value for my game. So a new field called "money" that will hold a value.
However, I'm not exactly sure how to go about doing so.
I took a look at the documentation and found things like .add but I wasn't sure exactly what was going on in the code.
Does anyone know a way to do this?
In the data browser, there is a "+ Col" button which allows you to add another field to your class. You can then set the name of the field and it's type.
You can also do this from their SDK's by simply setting the field, even if you have not added it via the data browser.
Here is what the Parse docs say regarding this:
Storing data through the Parse REST API is built around a JSON encoding of the object's data. This data is schemaless, which means that you don't need to specify ahead of time what keys exist on each object. You simply set whatever key-value pairs you want, and the backend will store it.
Source: https://parse.com/docs/rest#objects

Resources