Bot Framework Composer does not seem to interpret "if" well in the schema - bot-framework-composer

This schema is perfectly json-validated but does not work in Bot-Framework-Composer. To be exact, when "has" is "true" the "secondFace" object MUST be set, when "has" is "false" it must be absent.
The Bot Framework Composer validates correctly if "has" is true, while if "has" is "false" it continues to request to set the "secondFace" object. Is it a composer bug or is there anything to do, perhaps at the composer's form-UI level?
"hasSecondFace": {
"type": "object",
"title": "Has second face for comparison ?",
"additionaProperties": true,
"properties": {
"has": {
"type": "boolean",
"default": true,
"title": "Has Second Face",
"description": "If true ha second face else No"
},
"secondFace": {
"title": "Second face to be compared",
"additionalProperties": true,
"required": [
"type",
"param"
],
"oneOf": [
{
"type": "object",
"title": "From Storage",
"properties": {
"type": {
"const": "fromFile"
},
"param": {
"$ref": "schema:#/definitions/stringExpression",
"title": "Storage key",
"description": "key name of the blob"
}
}
},
{
"type": "object",
"title": "image stream",
"properties": {
"type": {
"const": "fromKey"
},
"param": {
"$ref": "schema:#/definitions/stringExpression",
"title": "Stream of second face",
"description": "Second face to compare"
}
}
}
]
}
},
"if": {
"properties": {
"has": { "const": true }
},
"required": [ "has" ]
},
"then": {
"required": [ "secondFace" ]
},
"else": {
"not": { "required": [ "secondFace" ] }
}
}
}

Related

No operations defined in spec! && Resolver error Cannot read properties of undefined (reading 'api')

I have this error in my node JS in swagger-ui-express I don`t know how to fix it
enter image description here
this is the code in the index.js file
in this code I`am tryin to call the json file that I make and call it swagger.json
const swaggerUi = require('swagger-ui-express'), swaggerDocument = require('./swagger.json')
app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerDocument))
that the pic of the beggin of the code
enter image description here
but I`am think that the error is here in this json file
"paths": {
"/api/category": {
"tages": [
"Category"
],
"summery": [
"Get all Categories"
],
"parameters": [
{
"name": "categoryName",
"in": "query",
"required": false,
"description": "Category name",
"type": "string"
},
{
"name": "page",
"in": "query",
"required": false,
"description": "Page Number",
"type": "integer",
"default": 1
},
{
"name": "PageSize",
"in": "query",
"required": false,
"type": "integer",
"default": 10
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/ServiceResponse"
}
}
}
},
"post": {
"tages": [
"Category"
],
"summery": "Create Category API",
"parameters": [
{
"name": "categoryName",
"in": "formDate",
"descripition": "Category Name",
"required": true,
"type": "string"
},
{
"name": "CategoryDescription",
"in": "formDate",
"descripition": "Category Description",
"type": "string"
},
{
"name": "Category Image",
"in": "formDate",
"descripition": "Category Image",
"type": "file"
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/ServiceResponse"
}
}
}
}
},
There are some typos and syntax errors:
The "/api/category" path is missing the "get": node that would wrap the GET operation definition. It should look like this:
"paths": {
"/api/category": {
"get": {
"tags": ...
"tages" should be "tags".
"summery": [...] should be replaced with:
"summary": "Get all Categories",
"in": "formDate" should be "in": "formData" ("a" at the end).
"descripition" should be "description".
Paste your OpenAPI JSON into https://editor.swagger.io - it will show all errors.

How to create message with Slack Block Kit, Bolt and Python?

I created the following BLOCK but cannot figure out how to use it within a /Command. It shows fine when used within the ack({...}) but does nothing when I use say({...}). The only other way is the client.dialog with type: modal but that is not what I want.
I simple need to know how to respond using my JSON block kit code. Any help is appreciated.
{
"attachments": [
{
"blocks": [
{
"type": "context",
"elements": [
{
"type": "plain_text",
"text": user_id + ", this was your question",
"emoji": True
}
]
},
{
"type": "section",
"text": {
"type": "plain_text",
"text": question,
"emoji": True
}
},
{
"type": "context",
"elements": [
{
"type": "plain_text",
"text": "Here's what I found",
"emoji": True
}
]
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": answer
}
},
{
"type": "divider"
},
{
"type": "section",
"text": {
"type": "plain_text",
"text": "Info",
"emoji": True
}
},
{
"type": "context",
"elements": [
{
"type": "mrkdwn",
"text": "*Author:* " + author
}
]
},
{
"type": "context",
"elements": [
{
"type": "mrkdwn",
"text": "*Book:* " + booktitle
}
]
},
{
"type": "context",
"elements": [
{
"type": "mrkdwn",
"text": "*Page:* " + str(page_num)
}
]
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": content
}
},
{
"type": "divider"
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "Was this helpful?"
},
"accessory": {
"type": "static_select",
"placeholder": {
"type": "plain_text",
"text": "please select an answer from the drop-down",
"emoji": True
},
"options": [
{
"text": {
"type": "plain_text",
"text": "*This was spot on*",
"emoji": True
},
"value": "1"
},
{
"text": {
"type": "plain_text",
"text": "*This was somewhat helpful*",
"emoji": True
},
"value": "0"
},
{
"text": {
"type": "plain_text",
"text": "*This was not helpful*",
"emoji": True
},
"value": "-1"
}
],
"action_id": "static_select-action"
}
}
]
}
]
}
EDIT
could this work?
client.chat_postMessage(
channel=event['channel'],
blocks=[
{...})
EDIT
#app.command("/q")
def q_command(client, event, ack, command):
ack("Gotcha! Let me take a look...")
user_id = event.get("user")
#...
client.chat_postMessage(
channel=event['channel'],
blocks=[
{ ... }])
What you mentioned will work.
Although, if you just want to respond to the same channel/dm where the command was invoked, you should use response_url received in the event payload.
https://api.slack.com/interactivity/handling#message_responses
let res = await axios.post(rsp_url, {
blocks: blocks
});
For further reading :
You can also check the following documentation.
SDK : https://slack.dev/python-slack-sdk/webhook/index.html#response-url
Message Types: https://slack.dev/python-slack-sdk/web/index.html#messaging

Unable to update the Knowledge in QnA maker

Unable to update the Knowledge in QnA maker whereas i am able to add the data to my Knowledge Base.Below is my update related REQUEST object
references: https://github.com/Azure-Samples/cognitive-services-qnamaker-java/blob/master/update-knowledge-base.java
{
"update": {
"qnaList": [
{
"id": 0,
"answer": "[92 Newcastle Court Roanoke, VA 24012](https://www.google.com/)",
"questions": [
"Where is Virginia located",
"What is the address of Roanoke",
"Roanoke address",
"Roanoke location"
],
"metadata": [
{
"name": "fragmenttype",
"value": "location"
},
{
"name": "locationname",
"value": "Roanoke"
},
{
"name": "type",
"value": "locationinfo"
}
]
},
{
"id": 1,
"answer": "[880 Oakwood St.Billerica, MA 01821](https://www.google.com/)",
"questions": [
"Where is Billerica located",
"What is the address of Billerica",
"Billerica address",
"Billerica location"
],
"metadata": [
{
"name": "fragmenttype",
"value": "location"
},
{
"name": "locationname",
"value": "Billerica"
},
{
"name": "type",
"value": "locationinfo"
}
]
}
]
}
}
and error response is:
{
"error": {
"code": 12,
"message": "Parameter is null",
"target": null,
"details": null,
"innerError": null
}
}
Your API call should be as below format.
More information can be found here
"update": {
"name": "QnA Maker FAQ Prompts Bot",
"qnaList": [
{
"id": 2,
"answer": "You can use our REST apis to create a KB. See here for details: https://learn.microsoft.com/en-us/rest/api/cognitiveservices/qnamaker/knowledgebase/create",
"source": "Custom Editorial",
"questions": {
"add": [],
"delete": []
},
"metadata": {
"add": [],
"delete": []
}
}
]
}

How to add multible accepted variables to Tag

I can't figure out a way to assign multible accepted Variables on a single tag.
Say we have "Environment Tag"
I want the only accepted variables to be "Production, Testing, Pending"
However i've only been able to assign one Variable per Tag.
I've tried using pre-built policys and build around them. As i'm fairly new to policies.
I have a tag "Environment"
I've created the tag Environment on the sub, so it appears in the dropdown menu.
I've tried to create multible variables in the variable section, however i can only create one.
I can get it working with one variable, such as production, but if i assign more than one variable in the text box it just adds it as one value, i've tried seperation with ("',;:) Nothing seems to work.
{
"properties": {
"displayName": "Require tag and its value",
"policyType": "BuiltIn",
"mode": "Indexed",
"description": "Enforces a required tag and its value. Does not apply to resource groups.",
"metadata": {
"category": "Tags"
},
"parameters": {
"tagName": {
"type": "String",
"metadata": {
"displayName": "Tag Name",
"description": "Name of the tag, such as 'environment'"
}
},
"tagValue": {
"type": "String",
"metadata": {
"displayName": "Tag Value",
"description": "Value of the tag, such as 'production'"
}
}
},
"policyRule": {
"if": {
"not": {
"field": "[concat('tags[', parameters('tagName'), ']')]",
"equals": "[parameters('tagValue')]"
}
},
"then": {
"effect": "deny"
}
}
},
"id": "/providers/Microsoft.Authorization/policyDefinitions/1e30110a-5ceb-460c-a204-c1c3969c6d62",
"type": "Microsoft.Authorization/policyDefinitions",
"name": "1e30110a-5ceb-460c-a204-c1c3969c6d62"
}
When inputting the TAG, and Variable
"parameters": {
"tagName": {
"type": "String",
"metadata": {
"displayName": "Tag Name",
"description": "Name of the tag, such as 'environment'"
}
"tagValue": {
"type": "String",
"metadata": {
"displayName": "Tag Value",
"description": "Value of the tag, such as 'production'"
}
I'd like to know if it's possible to add a secondary tagvalue "Tagvalue1,2,3 ect"
"tagValue": {
"type": "String",
"metadata": {
"displayName": "Tag Value",
"description": "Value of the tag, such as 'production'"
}
"tagValue1": {
"type": "String",
"metadata": {
"displayName": "Tag Value",
"description": "Value of the tag, such as 'Testing'"
}
"tagValue2": {
"type": "String",
"metadata": {
"displayName": "Tag Value",
"description": "Value of the tag, such as 'Pending'"
}
All other Variables for this tag should be rejected.
However i'm unable to get it working.
i think you need to use the in property. from examples:
"parameters": {
"allowedLocations": {
"type": "array",
"metadata": {
"description": "The list of allowed locations for resources.",
"displayName": "Allowed locations",
"strongType": "location"
},
"defaultValue": [ "westus2" ],
"allowedValues": [
"eastus2",
"westus2",
"westus"
]
}
}
and then you can reference it:
{
"field": "location",
"in": "[parameters('allowedLocations')]"
}
You can take an example from Azure documentation site: https://learn.microsoft.com/en-us/azure/governance/policy/samples/enforce-tag-on-resource-groups
If you do not need any parameters for the policy:
{
"properties": {
"displayName": "Enforce tag Environment and its value on resource groups",
"description": "Enforces a required tag and its value on resource groups.",
"mode": "All",
"parameters": {
},
"policyRule": {
"if": {
"allOf": [
{
"field": "type",
"equals": "Microsoft.Resources/subscriptions/resourceGroups"
},
{
"anyOf": [
{
"field": "tags[Environment]",
"notEquals": "Production"
},
{
"field": "tags[Environment]",
"notEquals": "Testing"
},
{
"field": "tags[Environment]",
"notEquals": "Pending"
}
]
}
]
},
"then": {
"effect": "deny"
}
}
}
}
with parameters :
{
"properties": {
"displayName": "Enforce tag and its value on resource groups",
"description": "Enforces a required tag and its value on resource groups.",
"mode": "All",
"parameters": {
"tagName": {
"type": "String",
"metadata": {
"description": "Name of the tag, such as costCenter"
}
},
"tagValue1": {
"type": "String",
"metadata": {
"description": "Value of the tag, such as production"
}
},
"tagValue2": {
"type": "String",
"metadata": {
"description": "Value of the tag, such as testing"
}
},
"tagValue3": {
"type": "String",
"metadata": {
"description": "Value of the tag, such as pending"
}
}
},
"policyRule": {
"if": {
"allOf": [
{
"field": "type",
"equals": "Microsoft.Resources/subscriptions/resourceGroups"
},
{
"anyOf" : [
{
"field": "[concat('tags[',parameters('tagName'), ']')]",
"notEquals": "[parameters('tagValue1')]"
},
{
"field": "[concat('tags[',parameters('tagName'), ']')]",
"notEquals": "[parameters('tagValue2')]"
},
{
"field": "[concat('tags[',parameters('tagName'), ']')]",
"notEquals": "[parameters('tagValue3')]"
}
]
}
]
},
"then": {
"effect": "deny"
}
}
}
}
If you are creating a policy from the Azure Portal, you do not need to copy displayName and description inside properties:
{
"mode": "All",
"policyRule": {
"if": {
"allOf": [
{
"field": "type",
"equals": "Microsoft.Compute/virtualMachines"
},
{
"anyOf": [
{
"field": "tags[Environment]",
"notEquals": "Production"
},
{
"field": "tags[Environment]",
"notEquals": "Testing"
},
{
"field": "tags[Environment]",
"notEquals": "Pending"
}
]
}
]
},
"then": {
"effect": "deny"
}
},
"parameters": {}
}
I've gotten this far thanks to your amazing help, however upon validating new VM's i get the following error, despite which value i type: Pending, Testing or Production
{
"code": "InvalidTemplateDeployment",
"message": "The template deployment failed because of policy violation. Please see details for more information.",
"details": [
{
"code": "RequestDisallowedByPolicy",
"target": "tester123",
"message": "Resource 'tester123' was disallowed by policy. Policy identifiers: '[{\"policyAssignment\":{\"name\":\"Enforce tag Environment\",\"id\":\"/subscriptions/f3434458-6c34-41bf-b159-04eff84fb1b8/providers/Microsoft.Authorization/policyAssignments/363b1c045401446eafdd29bf\"},\"policyDefinition\":{\"name\":\"Enforce tag Environment\",\"id\":\"/subscriptions/f3434458-6c34-41bf-b159-04eff84fb1b8/providers/Microsoft.Authorization/policyDefinitions/7be665bc-57a5-451d-b159-6cabcfd1042a\"}}]'.",
"additionalInfo": [
{
"type": "PolicyViolation",
"info": {
"policyDefinitionDisplayName": "Enforce tag Environment",
"evaluationDetails": {
"evaluatedExpressions": [
{
"result": "True",
"expressionKind": "Field",
"expression": "type",
"path": "type",
"expressionValue": "Microsoft.Compute/virtualMachines",
"targetValue": "Microsoft.Compute/virtualMachines",
"operator": "Equals"
},
{
"result": "True",
"expressionKind": "Field",
"expression": "tags[Environment]",
"path": "tags[Environment]",
"expressionValue": "Testing",
"targetValue": "Production",
"operator": "NotEquals"
}
]
},
"policyDefinitionId": "/subscriptions/f3434458-6c34-41bf-b159-04eff84fb1b8/providers/Microsoft.Authorization/policyDefinitions/7be665bc-57a5-451d-b159-6cabcfd1042a",
"policyDefinitionName": "7be665bc-57a5-451d-b159-6cabcfd1042a",
"policyDefinitionEffect": "deny",
"policyAssignmentId": "/subscriptions/f3434458-6c34-41bf-b159-04eff84fb1b8/providers/Microsoft.Authorization/policyAssignments/363b1c045401446eafdd29bf",
"policyAssignmentName": "363b1c045401446eafdd29bf",
"policyAssignmentDisplayName": "Enforce tag Environment",
"policyAssignmentScope": "/subscriptions/f3434458-6c34-41bf-b159-04eff84fb1b8",
"policyAssignmentParameters": {}
}
}
]
}
]
}
it would appear to me at least, that i fail because of wrong targetvalue. However I'd suppose that anyof the 3 options defined in policy definition would do?
Atleast i figured out how to only target this to our VM's, or at least i think i did.
There is a solution for restricting the values in basics called "allowedValues":
https://learn.microsoft.com/pl-pl/azure/governance/policy/concepts/definition-structure
https://learn.microsoft.com/pl-pl/azure/governance/policy/concepts/definition-structure#parameter-properties
"parameters": {
"allowedLocations": {
"type": "array",
"metadata": {
"description": "The list of allowed locations for resources.",
"displayName": "Allowed locations",
"strongType": "location"
},
"defaultValue": [ "westus2" ],
"allowedValues": [
"eastus2",
"westus2",
"westus"
]
}
}

Missing Subscription Key field in Swagger API connector (trough Azure API Management) in Logic App

I have created a REST API with a Swagger/OPEN API specification which I will like to consume trough a Azure API Management tenant in a Logic App.
When I download the specification it looks like this:
{
"swagger": "2.0",
"info": {
"title": "Leasing",
"version": "1.0"
},
"host": "ENDPOINT.azure-api.net",
"basePath": "/leasing",
"schemes": [
"http",
"https"
],
"securityDefinitions": {
"apiKeyHeader": {
"type": "apiKey",
"name": "Ocp-Apim-Subscription-Key",
"in": "header"
},
"apiKeyQuery": {
"type": "apiKey",
"name": "subscription-key",
"in": "query"
}
},
"security": [
{
"apiKeyHeader": []
},
{
"apiKeyQuery": []
}
],
"paths": {
"/{Brand}/groups": {
"get": {
"description": "Get a list of leasing groups on a brand",
"operationId": "GetGroups",
"parameters": [
{
"name": "Brand",
"in": "path",
"description": "Selection of possible brands",
"required": true,
"type": "string",
"enum": [
"Volkswagen",
"Audi",
"Seat",
"Skoda",
"VolkswagenErhverv",
"Porsche",
"Ducati"
]
}
],
"responses": {
"200": {
"description": "Returns a list of leasing groups",
"schema": {
"$ref": "#/definitions/GroupArray"
}
},
"400": {
"description": "If the brand is not valid",
"schema": {
"$ref": "#/definitions/Error"
}
}
},
"produces": [
"application/json"
]
}
}
},
"definitions": {
"Group": {
"type": "object",
"properties": {
"id": {
"format": "int32",
"type": "integer"
},
"name": {
"type": "string"
},
"description": {
"type": "string"
},
"leasingModelCount": {
"format": "int32",
"type": "integer"
},
"lowestMonthlyFee": {
"format": "int32",
"type": "integer"
}
}
},
"Error": {
"type": "object",
"properties": {
"code": {
"enum": [
"NotValidBrand",
"NotValidGroupId"
],
"type": "string",
"x-ms-enum": {
"name": "ErrorCode",
"modelAsString": true
}
},
"message": {
"type": "string"
}
}
},
"GroupArray": {
"type": "array",
"items": {
"$ref": "#/definitions/Group"
}
}
}
}
When I add this in a Logic App with the connector HTTP + Swagger I only get to define the {Brand} query input but not the various ways of using the Subscriptions key (header or query) as defined in SecurityDefiniations.
The whole securityDefinitions and security section are automatically generated in the Azure API Management service, but not recognized in Logic App.
See image of missing subscription key field:
What am I doing wrong?
Update
I have tried the following:
Usage of the 'Authentication' field (but this field is limited to certain types of auths flows https://learn.microsoft.com/en-us/azure/connectors/connectors-native-http#authentication)
Change the Logic App 'Http + Swagger'-action in code to add the header parameter, but this action converts the action to a simple 'Http' action and therfore loosing the automatic schema generation from Swagger.
I think you need to specify this in the Authentication-field in a JSON format. Something like:
{
"apiKeyHeader" : "your Ocp-Apim-Subscription-Key",
"apiKeyQuery" : "your subscription key"
}

Resources