I have a Teams Webhook receiving a message card in json format. There are some fields that are in nested format, but I am unable to access the values and display that in the webhook notification.
eg.
a{
b{
c: "XYZ",
d:{
m:1,
n:2}
}
}
I want to loop on b and access every key value. or directly access m
Related
I want to define a gRPC endpoint, that when called, returns some initial data and afterwards a stream of data. For example in a game it could create a lobby and return some initial data about the lobby to the creator and afterwards stream an event every time a player joins.
I want to achieve something like this:
message LobbyData{
string id = 1;
}
message PlayerJoin{
string id = 2;
}
service LobbyService {
rpc OpenLobbyAndListenToPlayerJoins(Empty) returns (LobbyData, stream PlayerJoin);
}
Unfortunately this is not possible so I have 2 options:
Option 1 (not what a want)
Creating two seperate RPCs, and call them sequentially on the client:
service LobbyService {
rpc OpenLobby(Empty) returns (LobbyData);
rpc ListenToPlayerJoins(LobbyData) returns (stream PlayerJoin);
}
This however creates the problem that players can join the lobby possibly before the second RPC from the client (ListenToPlayerJoins) reaches the server. So on the server we would need additional logic to open the lobby only after the ListenToPlayerJoins RPC from the creator has arrived.
Option 2 (also not what I want)
Use a single RPC with a sum type:
message LobbyDataOrPlayerJoin{
oneof type {
LobbyData lobby_data = 1;
PlayerJoin player_join = 2;
}
}
service LobbyService {
rpc OpenLobbyAndListenToPlayerJoins(Empty) returns (stream LobbyDataOrPlayerJoin);
}
This would allow for just one RPC, where the first element of the stream is a LobbyData object and all subsequent elements are PlayerJoins. What is not nice about this is that all streamed events after the first one are PlayerJoins but the client receives them still as the sum type LobbyDataOrPlayerJoin. Which is not clean.
Both options seem to me like workarounds. Is there a real solution to this problem?
I have json data asset in my Springboot powered web-app as follows
webapp/asset/labels.json
webapp/asset/dept1/labels.json
webapp/asset/dept2/labels.json
From the UI layer, a REST call occurs to fetch the labels (http://server/asset/labels.json). Now I want to dynamically fetch the contents of the labels json overwritten
with /dept1/labels.json-if the person belongs to dept1,
with /dept2/labels.json-if the person belongs to dept2.
labels.json
{"Foo" : "1","Bar" : "X"}
dept1/labels.json
{"Foo" : "2"}
dept2/labels.json
{"Bar" : "Y"}
Expected Json content expected by front-end when /asset/labels.json is invoked
For Employee who doesn't belong to Dept1 or Dept2
{"Foo" : "1","Bar" : "X"}
For Employee who belong to Dept1
{"Foo" : "2","Bar" : "X"}
For Employee who belong to Dept2
{"Foo" : "1","Bar" : "Y"}
I tried various approaches but in most cases I ended up custom implementation for each API. I have hundreds of json to handle, so I am wondering if there is a way to come up with a custom framework/utility which can handle for all JSON files.
You would have an API endpoint which will return the correct JSON.
In the API endpoint method you would follow the below steps:
First load the base JSON file into a Map say baseMap.
Next based on the user's dept you load the dept specific JSON into another Map say deptMap
then you run this line of code: baseMap.putAll(deptMap)
The putAll will override any keys coming from department specific JSON.
Note:
There will be only ONE end point and this end point will determine Employee either based on the employee name passed to it as query parameter or obtains it based on the logged in user
Below is the service spec:
service Cooler {
rpc saveThing (stream SaveRequest) returns (SaveReply);
}
I need to stream messages to to Cooler.saveThing(). All the SaveRequests have a common field author and unique fields per a Thing are price and name. How can I send the author only once?
Not working attempt - Multiple inputs
It would be a solution but it is not supported by protobuf yet.
service Cooler {
rpc saveThing (stream SaveRequest, Author) returns (SaveReply);
}
Not working attempt - Nested message
Every received element of SaveRequest will still contain author and an array of Things.
message SaveRequest {
message Thing {
int price = 1;
string name = 2;
}
repeated Thing things = 1;
string author = 2;
}
Possible solution
Grpc headers.
Question
How can I send the author only once?
I am using django rest framework documentation module to document my API.
I am facing a problem in the sense that nested serializers do not appear in my documentation, but only the outermost does.
As an example I have the following code:
class MyFirstSerializer(serializers.Serializer):
some_data = serializers.CharField(help_text="a number")
more_data = serializers.CharField(help_text="a letter")
class MySecondSerializer(serializers.Serializer):
email = serializers.EmailField(help_text="the email address")
number = serializers.CharField(help_text="a number")
another_serializer = MyFirstSerializer(help_text='a JSON structure')
The way the program works, is by having a nested JSON structure. However the documentation modules on mentions the fact that another_serializer is a field, and does not show what kind of data is supposed to be passed, somethinng like:
POST your/endpoint/
Parameter Description
email the email address
number a number
another_serializer a JSON structure
I would like a way for the documentation to be done recursively on all my field, in order to have a complete description of my endpoints, something like:
POST your/endpoint/
Parameter Description
email the email address
number a number
another_serializer
some_data a number
more_data a letter
Is there any way of getting the CanonicaForm in the C#-code after an intent? The LuisResult contains EntityRecommendation(s) but no info about which canonicalForm/sublist, just the written entity/synonym in EntityRecommendation.Entity and the name of the WHOLE List Entity in EntityRecommendation.Type.
Assume "MyEntity" is a List entity, and one of its normalized values is "Check Out" with a synonym of "checkout"
If LUIS returns the synonym ("checkout") as the entity, the normalized value ("Check Out") can be retrieved as follows:
bool isEventType = result.TryFindEntity("MyEntity", out EntityRecommendation entityRecommendationEventType);
if (isEventType)
{
stringSynonym = entityRecommendationEventType.Entity;
stringNormalized = ((List<object>)entityRecommendationEventType.Resolution["values"])[0].ToString();
}
There is no way to retrieve this from LUIS. The only way you can do this is to export the list from LUIS and store it in your bot. You can do this via the JSON file exported from LUIS.