microsoft / botframework-solutions

Welcome to the Bot Framework Solutions repository which is the home for a set of templates and solutions to help build advanced conversational experiences using Azure Bot Service and Bot Framework. Microsoft Bot Framework is a comprehensive framework for building enterprise-grade conversational AI experiences.
https://aka.ms/bfsolutionsdocs
MIT License
1.05k stars 528 forks source link

Unable to add generic connection to bot file #485

Closed gabog closed 5 years ago

gabog commented 5 years ago

Project Virtual Assistant

Description Hi, I am trying to add the AAD connection to my bot file from powershell and I am getting "SyntaxError: Unexpected token \ in JSON at position 1".

I am running the following command (that I copied and pasted from https://github.com/Microsoft/AI/blob/master/solutions/Virtual-Assistant/docs/virtualassistant-createvirtualassistant.md and just updated the connection name)

msbot connect generic --name "Authentication" --keys "{\"Azure Active Directory v2\":\"Azure Active Directory v2\"}" --bot GGVADevMaster.bot --url "portal.azure.net"

To Reproduce

  1. Ensure your bot file is unencrypted and it doesn't contain the generic connection for authentication.
  2. Run the command specified above from powershell and you'll get: image

Expected behavior I would like to be able to add the connection from the command line as described in the documentation.

Additional context As a workaround, I manually edited the bot file and added the following json fragment:

{
  "type": "generic",
  "configuration": { "Azure Active Directory v2": "Azure Active Directory v2" },
  "name": "Authentication",
  "url": "portal.azure.net"
}

Is this a bug? or am I doing something wrong?

lauren-mills commented 5 years ago

I think the key here might be Powershell having different escape characters. I usually use command prompt. I'll try it out and see if I can repro.

lauren-mills commented 5 years ago

I am able to repro. It works correctly in command prompt and gives the error in PS. I tried the string several different ways and haven’t gotten it working yet in PowerShell.

gabog commented 5 years ago

K, thanks, it does also work for me from command prompt (I normally use PS).

Regarding PS, I tried the PS option (with variables) and I get "Missing URL" (probably something with the quotes also)

image

lauren-mills commented 5 years ago

This issue provides a workaround for PS #191

I'll add this to known issues in the meantime.

progutskyi commented 5 years ago

Mentioned workaround didn't work for me. After messing with this for a few hours I've found the working solution:

msbot connect generic --bot MyBot.bot --url https://westeurope.api.cognitive.microsoft.com --keys '{\"subscriptionKey\":\"some_key\"}' --name Name

Json should be wrapped in '' and all properties should have "" properly escaped with \ and no spaces in JSON if used from cmd

lauren-mills commented 5 years ago

This works for me in PowerShell:

msbot connect generic --name Authentication --url portal.azure.com  --% --keys "{\"O365\":\"Azure Active Directory v2\"}"