Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how can we best get the DirectLine secret of a specific site in the DirectLine channel using an ARM template? #34829

Closed
hansmbakker opened this issue Jul 10, 2019 — with docs.microsoft.com · 6 comments

Comments

Copy link
Contributor

hansmbakker commented Jul 10, 2019

Main question: how can we best get the DirectLine secret of a specific site in the DirectLine channel using an ARM template?

I found the listChannelWithKeys function. This is a semi-documented function on the Microsoft.Bot/botservice/channels provider.

It is listed in Azure Resource explorer on the Actions tab of a channel and it is explained in this stackoverflow answer, but it is not in the ARM template reference.

However Visual Studio code does not recognize it as a function to be used in ARM templates. Furthermore, the listChannelWithKeys returns the properties of all sites in the requested channel, while I want the secret for a specific site.

I would hope to be able to do something like this:

{
  "$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "outputs": {
    "directLineSecret": {
      "type": "string",
      "value": "[listChannelWithKeys(resourceId('Microsoft.BotService/botServices', parameters('botId'), 'channels', 'DirectLineChannel', 'sites', 'mysitename'), '2018-07-12').key]"
    }
  }
}

How can I best do that?

Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

@hansmbakker hansmbakker changed the title listChannelWithKeys function to get DirectLine secret in bot registration how can we best get the DirectLine secret of a specific site in the DirectLine channel using an ARM template? Jul 10, 2019
@femsulu
Copy link
Member

femsulu commented Jul 10, 2019

Thanks for your comment. We are actively investigating and will get back to you shortly. Thanks for your patience.
@tfitzmac - any ideas on this ?

@tfitzmac
Copy link
Contributor

@hansmbakker - thanks for this question. You can use that function in a template with syntax like:
"outputs": {
"directLineSecret": {
"value": "[listChannelWithKeys('/subscriptions/{sub-id}/resourceGroups/{rg}/providers/Microsoft.BotService/botServices/{bot}/channels/DirectLineChannel', '2018-07-12').properties.properties.sites[0].key]",
"type": "string"
}
}

Given that it is a list function, I don't know how you would limit it to one site. I don't see any parameters in the function that would allow you to limit it.

I'll add this function to the list of available functions in a template.

@hansmbakker
Copy link
Contributor Author

Great, I'll try it tomorrow! Thank you for your support!

@hansmbakker
Copy link
Contributor Author

hansmbakker commented Jul 12, 2019

@tfitzmac I saw that it works when the site exists.

The things that do not work yet are

Where can I best add feedback to the arm schema reference documentation? On https://docs.microsoft.com/en-us/azure/templates/microsoft.botservice/2018-07-12/botservices/channels there is no github feedback integration and the contributors link at the top links to a repository that is private, I believe. The azure-docs repo looks like the best alternative?

  "resources": [
    {
      "type": "Microsoft.BotService/botServices",
      "apiVersion": "2017-12-01",
      "name": "[parameters('botId')]",
      "location": "global",
      "sku": {
        "name": "[parameters('sku')]"
      },
      "kind": "sdk",
      "properties": {
        "name": "[parameters('botId')]",
        "displayName": "My Bot Name",
        "endpoint": "[parameters('botMessagesEndpoint')]",
        "msaAppId": "[parameters('appId')]",
        "developerAppInsightsApplicationId": "[parameters('insightsAccountName')]",
        "developerAppInsightKey": "[reference(resourceId('microsoft.insights/components/', parameters('insightsAccountName')), '2015-05-01').InstrumentationKey]"
      },
      "resources": [
        {
          "name": "DirectLineChannel",
          "apiVersion": "2018-07-12",
          "location": "global",
          "type": "channels",
          "dependsOn": [
            "[resourceId('Microsoft.BotService/botServices', parameters('botId'))]"
          ],
          "properties": {
            "channelName": "DirectLineChannel",
            "sites": [
              {
                "siteName": "TokenGeneration",
                "isEnabled": true,
                "isV1Enabled": true,
                "isV3Enabled": true,
                "isSecureSiteEnabled": true,
                "isBlockUserUploadEnabled": true,
                "trustedOrigins": "[parameters('trustedOrigins')]"
              }
            ]
          }
        }
      ]
    }

I fill the trustedOrigins parameter with an array containing one string of a the base url of my bot.

The output works if I write it like this, and if the site got created (otherwise sites[0] does not exist):

"outputs": {
    "directLineSecret": {
      "type": "string",
      "value": "[listChannelWithKeys(concat(resourceId('Microsoft.BotService/botServices', parameters('botId')), '/channels/DirectLineChannel'), '2018-07-12').properties.properties.sites[0].key]"
    }
  }

@PRMerger6 PRMerger6 added the Pri1 label Sep 9, 2019
@esoler-sage
Copy link

By the way,

you can take the resource id directly by setting up the segment:

"outputs": {
    "directLineSecret": {
      "type": "string",
      "value": "[listChannelWithKeys(resourceId('Microsoft.BotService/botServices/channels', parameters('botId'), 'DirectLineChannel'), '2018-07-12').properties.properties.sites[0].key]"
    }
  }

as in this post explains Azure/azure-quickstart-templates#1965

@tfitzmac
Copy link
Contributor

tfitzmac commented Jan 4, 2024

I believe the reference docs have been updated with the required information.
#please-close

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants