Cognigy / Cognigy-CLI

Cognigy-CLI is a series of tools meant to aid Cognigy.AI developers in maintaining local copies of their virtual agent projects.
Other
7 stars 6 forks source link

cognigy translate: Microsoft Translator: missing Ocp-Apim-Subscription-Region header #124

Open tgbv opened 1 year ago

tgbv commented 1 year ago

Lately, Microsoft Translator requires the region header as well. The command cognigy translate does not ask for region, making the translation via Microsoft feature impossible.

$ cognigy --version

# 1.4.0

$ cognigy translate --help

# Usage: cognigy translate [options] <resourceType> <resourceName>
# 
# Translate a resource
# 
# Options:
#   -l, --localeName <localeName>           locale to process
#   -fl, --fromLanguage <fromLanguageCode>  language to translate from
#   -tl, --toLanguage <targetLanguageCode>  language to translate to
#   -tr, --translator <translator>          the translation tool, google, microsoft or deepl
#   -ti, --translateIntents                 adds localization to Flow Intents
#   -tn, --translateNodes                   adds localization to Flow Nodes
#   -k, --apiKey <apiKey>                   the translator api key
#   -y, --forceYes                          skips warnings and overwrites all content
#   -h, --help                              display help for command

$ cognigy translate -l Polish -fl en -tl pl -tr microsoft -tn -k MS_TRANSLATOR_API_KEY flow FLOW_NAME

# throws axios error: 403 Unauthorized, but API key is correct.

Reference: https://learn.microsoft.com/en-us/answers/questions/1192881/how-to-get-microsoft-translator-api-key

tgbv commented 1 year ago

After digging deeper into MS Docs, this looks more like a feature request: https://learn.microsoft.com/en-us/azure/ai-services/translator/reference/v3-0-reference#authenticating-with-a-regional-resource as there are multiple ways to authenticate with MS Translator.

Nevertheless, it should be implemented. I made a pull request in which apiRegion is optional & used only for Microsoft Translator requests.