Closed Roaders closed 2 months ago
ok... I was wrong. id
is defined on Context
but it is an object. This is what we can use.
@Roaders The type and the interface represent the same thing in two different encodings (TypeScript for the API, TypeScript generated from JSON schema in the Desktop Agent Communicaiton protocol). They are functionally equivalent (and empty IntentResult object represent a void
return - you should still send that message at indicates that the handler finished and there was a void
result).
id
may not be present in all context types. Its very common, but technically optional.
Both Context
and Channel
have type
fields - but the values for Channel
are constrained to: "user" | "app" | "private"
so I would use that as the most reliable means of differentiation. We should probably ban those as COntext types to be sure!
yes I saw the values for type
but currently there is nothing that stops you creating a a context object with a type of user
- unless I am missing something. I am not sure how easy it would be to ban them using typescript either.
Technically the context spec requires contexts to be namespaces (fdc3.
for standard types) - but this is hard to enforce via typescript. We could state reserved values.
In TypeScript we differentiate by looking for functions like addContextListener
, but you don't have that in JSON. So... id is either a string or object, or you look for the displayMetadata
property. No compelling answers I'm afraid.
well in typescript you could actually have: ts
type: `${string}.${string}`;
which would require that the type does have a period in it. This may well break apps though that are using context with no period.
I am not sure how that would work with the json schemas though
JSON schema can apply regex to control strings - but it doesn't generate out into TypeScript through QUicktype at the moment...
Question Area
Question
I am currently trying to implement handling the result of the
IntentHandler
when we are callingraiseIntent
. The return type ofIntentHandler
is:and the
IntentResult
(with a duplicate name) that we need to send within theRaiseIntentResultResponse
is:What is the best of determining if the result returned from the
IntentHandler
is aChannel
or aContext
?Context
defines atype: string
property (everything else is optional) which is also present onChannel
.Channel
definesid: string
(the only other required field) but it is quite possible thatid
is also present onContext
as we have[property: string]: any;
.As far as I can see there is no way of reliably telling what has been returned. The closet we could come is checking for
id
but that is not infallible.