05-02-2024 13:32 PM - last edited 05-02-2024 13:46 PM
The main idea of this sample is to show the user how a PVA Bot can be connected using DirecLine API and using all its topics in di
fferent languages, by using a middleware (Azure Bot) to translate the messages between the user and the PVA Bot. The middleware will be using Cognitive services to translate the texts during the entire conversation.
Follow this link to have more information on how to create the Translator service.
These are the Bot resources needed by the sample:
Azure Translator is a cloud-based machine translation service that is part of the Azure Cognitive Services family of REST APIs. Azure resources are instances of services that you create on the Azure portal.
Subscription: Select one of your available Azure subscriptions.
Resource Group: You can create a new resource group or add your resource to a pre-existing resource group that shares the same lifecycle, permissions, and policies.
Resource Region: Choose Global unless your business or application requires a specific region. If you're planning on using the Document Translation feature with managed identity authentication, choose a non-global region.
Name: Enter the name you have chosen for your resource. The name you choose must be unique within Azure.
Pricing tier: Select a pricing tier that meets your needs:
If you've created a multi-service resource, you'll need to confirm additional usage details via the checkboxes.
Select Review + Create.
Review the service terms and select Create to deploy the resource.
After your resource has successfully deployed, select Go to the resource.
All Cognitive Services API requests require an endpoint URL and a read-only key for authentication
Authentication keys. Your key is a unique string that is passed on every request to the Translation service. You can pass your key through a query-string parameter or by specifying it in the HTTP request header.
Endpoint URL. Use the Global endpoint in your API request unless you need a specific Azure region or custom endpoint. See Base URLs. The Global endpoint URL is api.cognitive.microsofttranslator.com.
An App registration is needed to deploy an Azure Bot. The following sections will give more details on this task.
The user needs to have sufficient permissions to register an App in the Azure AD tenant. Check this link for more information about it.
Credentials allow an application to authenticate as a user, requiring no interaction from a user at runtime.
The bot can be deployed using these two methods:
Follow these steps to deploy the bot using the Azure CLI. This approach assumes that the resource group already exists.
Download the Azure CLI (if needed) from this link.
Download the Zip file containing the Bot source code from this repo.
Open the appsettings.json file located in the Bot folder. The file should look like this image.
Update the following settings, ommiting the optional ones:
TokenEndpoint: https://powerva.microsoft.com/api/botmanagement/v1/directline/directlinetoken
NOTE: To obtain the bot id go to Settings -> Channels -> Mobile App and copy the token endpoint where you will find the bot id
BotName: The name of the PVA bot.
TenantId: Bot Tenant id. This can be obtained from the details page on PVA under the manage option.
TranslatorKey: The value in the Azure secret key for the Translator resource.
TranslatorCategoryId: The category id for the translator service's custom dictionary (optional). For example:
"TranslatorCategoryId": { "en": { "dictionary": "category-id" } }
BotLanguage: your PVA bot's language (e.g: en).
DetectLanguageOnce: true/false value to enable language detection on the first message or every message received from the user.
GetLanguageFromUri: true/false value to get the language to be used in the conversation. It will be received through the connection endpoint (optional). For example:
http://localhost:3979/api/messages/es
PVATopicExceptionTag: Tag to be used as an exception to avoid the translation of user's responses (optional).
EscalationPhrases: Phrases that will be used to identify and handle the hand-off process to a human agent in Omnichannel (optional).
MicrosoftAppId: App id obtained from the App registration Overview page.
MicrosoftAppPassword: Secret configured for the App registration.
4. Open the CMD or Powershell console and login to Azure using the following command:
az login
5. Update the parameters-for-template-BotApp-with-rg.json file with the proper information, this file can be found in the Bot root folder under the DeploymentTemplates\DeployUseExistResourceGroup directory. The file should look like this image.
Update the following settings, ommiting the optional ones:
6. Deploy the BotApp using the following command. These parameters need to be specified:
az deployment group create --resource-group "resource-group-name" --template-file template-BotApp-with-rg.json --parameters "parameters-for-template-BotApp-with-rg.json"
Once executed a message like the following will be received:
7. Update the parameters-for-template-AzureBot-with-rg.json file with the proper information, this file can be found in the Bot root folder under the DeploymentTemplates\DeployUseExistResourceGroup directory. The file should look like this image.
Update the following settings, ommiting the optional ones:
8. Deploy the AzureBot using the following command. These parameters need to be specified:
az deployment group create --resource-group "resource-group-name" --template-file template-AzureBot-with-rg.json --parameters "parameters-for-template-AzureBot-with-rg.json"
Once executed a message like the following will be received:
9. Execute the following command:
az bot prepare-deploy --lang Csharp --code-dir "." --proj-file-path "<my-cs-proj>"
Create a zip file with the solution content. This zip file should contain all the folders and files included in the Bot directory.
11. Execute the deployment command. These parameters need to be specified:
12. Now the bot and its components are deployed, so you can move on to the "How to use the bot" section.
In Azure DevOps, open the Service connections page from the project settings page. In TFS, open the Services page from the "settings" icon in the top menu bar.
Choose + New service connection and select Azure Resource Manager.
3. Choose Service Principal (manual) option and enter the Service Principal details.
4. Enter a user-friendly Connection name to use when referring to this service connection.
5. Select the Environment name (such as Azure Cloud, Azure Stack, or an Azure Government Cloud).
6. If you do not select Azure Cloud, enter the Environment URL. For Azure Stack, this will be something like https://management.local.azurestack.external
7. Select the Scope level you require:
8. Enter the information about your service principal into the Azure subscription dialog textboxes:
You can obtain this information if you don't have it by hand downloading and running this PowerShell script in an Azure PowerShell window. When prompted, enter your subscription name, password, role (optional), and the type of cloud such as Azure Cloud (the default), Azure Stack, or an Azure Government Cloud.
9. Choose Verify connection to validate the settings you've entered.
10. After the new service connection is created:
11. If required, modify the service principal to expose the appropriate permissions. For more details, see Use Role-Based Access Control to manage access to your Azure subscription resources. This blog post also contains more information about using service principal authentication.
Login to your Azure dev account
On the left menu click on pipelines -> pipelines
3. Select New pipeline
4. On the connect window, select the GitHub option to connect the pipeline to your repository
5. Select your repository
6. On the configure your pipeline window select the Existing Azure Pipelines YAML file option
7. Select the branch and path where your YAML file is located inside your repository
8. On the top right corner, click on Save
9. Complete the commit message, description, select your branch and click on save to commit the changes to your repository.
10. On the top right corner, click on variables and setup the following variables:
TokenEndpoint: https://powerva.microsoft.com/api/botmanagement/v1/directline/directlinetoken
BotId: The id of the PVA bot.
BotName: The name of the PVA bot.
TenantId: Bot Tenant id. This can be obtained from the details page on PVA under the manage option.
TranslatorKey: The value in the Azure secret key for the Translator resource.
TranslatorRegion: The region of the multi-service or regional translator resource.
TranslatorCategoryId: The category id for the translator service's custom dictionary (optional). For example:
"TranslatorCategoryId": { "en": { "dictionary": "category-id" } }
BotLanguage: your PVA bot's language (e.g: en).
DetectLanguageOnce: true/false value to enable language detection on the first message or every message received from the user.
GetLanguageFromUri: true/false value to get the language to be used in the conversation. It will be received through the connection endpoint (optional). For example:
http://localhost:3979/api/messages/es
PVATopicExceptionTag: Tag to be used as an exception to avoid the translation of user's responses (optional).
EscalationPhrases: Phrases that will be used to identify and handle the hand-off process to a human agent in Omnichannel (optional).
Note: For the last variables, make sure to also check the "Keep this value secret" box.
11. On the top right corner, click on Run
12. Select the Branch/tag and commit where the pipeline version you want to run is located
13. Now the bot and its components are deployed, so you can move on to the next section.
After the bot is deployed it can be tested using one of the following methods:
Install the Bot Framework Emulator in case it is not already installed from this link. Here is another link with additional information on how to use the Bot Framework Emulator tool.
Get the messaging endpoint of your bot by going to the Azure Portal and clicking on the Azure Bot resource
Go to the Azure Portal and select your Azure bot
On the left panel, click on Test in Web Chat under settings
If the Bot is not working properly after the deployment, the values of the deployed appsettings can be validated from the Azure Portal instead of doing it locally and deploying again. To do this, follow these steps:
Go to the Azure Portal and select your Azure bot webapp.
On the left panel, under development tools, click on App Service Editor and then click on open editor.
3. A new window will be opened with the appsettings and all files.
4. These settings will be saved automatically.
Exceptions can be configured to avoid the translation of a particular user's response to a Bot question. This can be achieved using a custom PVA topic.
This scenario will enable Bot authors using PVA to set up a flag topic that will be used in other topics to indicate that the response to a particular question should not be translated. Steps to configure:
Create a new topic that will be used to flag the exception.
2. Edit the topic where the exception should be applied. The exception topic should be invoked before the question that will be sent to the user.
3. Edit the Bot appsettings file to configure the tag used for the topic created in step 1.
"PVATopicExceptionTag": "#DONOTTRANSLATE#",