Genesys Cloud - Main

 View Only


Discussion Thread View
Expand all | Collapse all

Data Actions: read Information from response header / AZURE AI Language

  • 1.  Data Actions: read Information from response header / AZURE AI Language

    Posted 11-10-2023 02:33

    Hello community,

    I try to integrate AZURE AI Language services, custom text classification. Problem is: I am able to send the request with a data action, via API but the response is empty. The information I need is in the header (location of the job I started). How do I access informations in the header?

    Is there a way like $.headers.attributename ? In developer Forum there was no single answer to that question. Maybe you can help?

    Best regards
    Christoph


    #ArchitectureandDesign
    #Integrations
    #Unsure/Other

    ------------------------------
    Christoph Domaschke
    CRONBANK AG
    ------------------------------


  • 2.  RE: Data Actions: read Information from response header / AZURE AI Language

    Posted 11-21-2023 23:59

    After you create the SMS with the agentless API, you can take that Conversation ID and use a Patch to update the attributes on the conversation using https://developer.genesys.cloud/devapps/api-explorer-standalone#patch-api-v2-conversations-messages--conversationId--participants--participantId--attributes, then you can use the conversation details API when the SMS comes back to read those attributes.  The only problem may be if the reply comes after 72 hours, you may not have the session still open, so you many need to use a query to find the last SMS to that number and get that conversation ID to read from.  A bit of work, but I think it is doable.  @Anton Vroon, what do you think - any other idea?



    ------------------------------
    Robert Wakefield-Carl
    ttec Digital
    Sr. Director - Innovation Architects
    Robert.WC@ttecdigital.com
    https://www.ttecDigital.com
    https://RobertWC.Blogspot.com
    ------------------------------



  • 3.  RE: Data Actions: read Information from response header / AZURE AI Language

    Posted 11-22-2023 02:03

    Hello Robert,
    I am really excited to get an answer to my topic, but actually I am completly lost. What is the connection between an SMS and my AZURE-AI-Language-API-Call?

    Best regards
    Christoph



    ------------------------------
    Christoph Domaschke
    CRONBANK AG
    ------------------------------



  • 4.  RE: Data Actions: read Information from response header / AZURE AI Language

    Posted 11-22-2023 10:42

    All done through API calls.  Your Azure code can write Attributes to the SMS conversation and tine inbound messaging flow can write to Azure using their APIs.  What exactly are you using the Azure API's for?  Is it just for classification or tagging?  If so, you can always do that in Genesys natively using Topics.  With the inbound messaging flow, you can send the text of the SMS out to MS and get back that as well then set that as participant data on the inbound SMS or use it for routing.



    ------------------------------
    Robert Wakefield-Carl
    ttec Digital
    Sr. Director - Innovation Architects
    Robert.WC@ttecdigital.com
    https://www.ttecDigital.com
    https://RobertWC.Blogspot.com
    ------------------------------



  • 5.  RE: Data Actions: read Information from response header / AZURE AI Language

    Posted 11-23-2023 02:45

    Thanks for clarifiying. Your solution sounds like a kind of middleware, based on something I (or someone) would have to code in AZURE. Did I understand you right? Manipulating participant data attributes is familar to me, I did that before with data actions and flow. What you suggest for SMS should work for my email-problem, too.

    Of course I would task a professional for that kind of middleware, but I am trying to figure out, whether there is a simpler way I am not aware of.
    I wrote some details in my answer to Anton Vroon.
    I really apreciate your help, thank you!

    Best regards
    Christoph



    ------------------------------
    Christoph Domaschke
    CRONBANK AG
    ------------------------------



  • 6.  RE: Data Actions: read Information from response header / AZURE AI Language

    Top 25 Contributor
    Posted 11-22-2023 15:23

    I think to help out further than what Robert has already suggested, we really need to know a bit more information.

    Like what are your trying to do here, what is the context, there might be a way to natively do what you are after in Genesys without the need for custom integration.

    What is the API call you are making, and it might be more of a question for MS if there response you are getting isn't right. Certainly the documentation for Azure Text Analysis returns results in standard JSON format, so it seems very odd that you are getting the response in a header. 



    ------------------------------
    Anton Vroon
    ------------------------------



  • 7.  RE: Data Actions: read Information from response header / AZURE AI Language

    Posted 11-23-2023 02:34

    Thanks für joning this discussion,
    I will explain the details:

    • I want to use AZURE AI Language, "Custom text classification" to classify my emails to different categories.
    • I want to send the e-mail-text via an API call.
      • Due to the documentation, Quickstart - chapter "Text Classification" (Quickstart - Custom text classification - Azure AI services | Microsoft Learn) I have to make an API-POST {ENDPOINT}/language/analyze-text/jobs?api-version={API-VERSION}
      • the documentation says about the response "You will receive a 202 response indicating success. In the response headers, extract operation-location. operation-location is formatted like this:

        {ENDPOINT}/language/analyze-text/jobs/{JOB-ID}?api-version={API-VERSION}

        You can use this URL to query the task completion status and get the results when task is completed."

      • Figuring out that API with Postman works fine. The JSON-Body is empty and the header holds the information as described in the documentation.
      • With that JOB-ID i could get the result of the job via GET {ENDPOINT}/language/analyze-text/jobs/{JOB-ID}?api-version={API-VERSION}
    • As explained I need to find a way to get that information from the header. Data Actions by Genesys Cloud do not seem to have the possibility to access data from the response header.

    I really apreciate, that you and Robert are spending your time on my problem. Thanks!

    Best regards,
    Christoph



    ------------------------------
    Christoph Domaschke
    CRONBANK AG
    ------------------------------



  • 8.  RE: Data Actions: read Information from response header / AZURE AI Language

    Posted 11-23-2023 12:04

    So, it sounds like you can create a Data Action in Genesys Cloud and use that in an Email Flow to send the body of the email over to Azure using the data action and get back a response that you can then process in the Email Flow for routing, skilling, et al.  Seems simple enough. 



    ------------------------------
    Robert Wakefield-Carl
    ttec Digital
    Sr. Director - Innovation Architects
    Robert.WC@ttecdigital.com
    https://www.ttecDigital.com
    https://RobertWC.Blogspot.com
    ------------------------------



  • 9.  RE: Data Actions: read Information from response header / AZURE AI Language

    Posted 11-24-2023 02:02

    That is the plan. But the answer from AZURE is an empty JSON body (what is correct due to ther documentation). The crucial information I need from that response is in the header: the job id. Is there a way to access the variables in the response header?



    ------------------------------
    Christoph Domaschke
    CRONBANK AG
    ------------------------------



  • 10.  RE: Data Actions: read Information from response header / AZURE AI Language

    Top 25 Contributor
    Posted 11-23-2023 15:05

    Hi Christoph,

    This makes sense, categorizing emails in Genesys natively is pretty simple with just doing contain expressions so can see why you want to go down this path.

    With DataActions, you can apply variables as inputs to header items, but I don't think you can assign the response header items to variables which is what you are after. You would yes instead need some middleware or lambda for example which you would create a DataAction call to, that would send the API request, grab the header info, then send the API request to get the result, then return that to the DataAction results.

    Only issue there might be the time it takes so be careful with the DataAction timeout settings.

    If you haven't already provided the above details to your post on the Developer Forum I would suggest you do so in case some one there knows of any extra tricks.



    ------------------------------
    Anton Vroon
    ------------------------------



  • 11.  RE: Data Actions: read Information from response header / AZURE AI Language

    Posted 11-24-2023 02:08

    You are saying that the REST API that returns a Job ID but not in a payload? Sounds like a pretty useless API.  I would skip the MS junk and just do what you need in Genesys. 



    ------------------------------
    Robert Wakefield-Carl
    ttec Digital
    Sr. Director - Innovation Architects
    Robert.WC@ttecdigital.com
    https://www.ttecDigital.com
    https://RobertWC.Blogspot.com
    ------------------------------



  • 12.  RE: Data Actions: read Information from response header / AZURE AI Language

    Posted 11-24-2023 02:13

    Yes, unfortunately MS made a strange design choice there. Thanks for your time, Robert!



    ------------------------------
    Christoph Domaschke
    CRONBANK AG
    ------------------------------



  • 13.  RE: Data Actions: read Information from response header / AZURE AI Language

    Posted 11-24-2023 02:11

    Hi Anton,
    thanks for your funded opinion. I will commission a programmer with that middleware. Thanks for your hint about DataAction timeouts. Robert suggested to use the participant-data-API to deliver the result will do the trick.
    I tried my luck in the developer forum without a response.

    Thanks for you help and your time!
    Best regards
    Christoph



    ------------------------------
    Christoph Domaschke
    CRONBANK AG
    ------------------------------



  • 14.  RE: Data Actions: read Information from response header / AZURE AI Language

    Posted 11-27-2023 13:41
    Edited by Max Gill 11-27-2023 14:01

    Azure AI - Language

    We standardize many of our AI services on Azure and we are very happy. Depending on the Azure AI Language task, some are synchronous responses (like Language Detection or Sentiment Analysis), while others are async with a JobID (like text summarization). 

    The "EntityRecognition", "KeyPhraseExtraction", and "PiiEntityRecognition" tasks can either be called sync or async. Azure supports the async model if you want to complete analysis on multiple text blocks. 

    For example, this API returns a result immediately:

    POST {Endpoint}/language/:analyze-text?api-version=2023-04-01

    https://learn.microsoft.com/en-us/rest/api/language/text-analysis-runtime/analyze-text?view=rest-language-2023-04-01&tabs=HTTP

    While this API returns a JobID:

    POST {Endpoint}/language/analyze-text/jobs?api-version=2023-04-01

    https://learn.microsoft.com/en-us/rest/api/language/text-analysis-runtime/submit-job?view=rest-language-2023-04-01&tabs=HTTP#keyphraselrotask 

    I see that you are using the async version. Try switching to something like:

    endpointUri = cogSvcEndpoint + "language/:analyze-text?api-version=2022-05-01";  //use the latest API, this is just from an older code block I quickly found
    
    //create JSON payload
    jsonBody = new JObject(
        new JProperty("kind", "EntityRecognition"),
        new JProperty("parameters", new JObject(
            new JProperty("modelVersion", "latest")
        )),
        new JProperty("analysisInput",
            new JObject(
                new JProperty("documents",
                    new JArray(
                        new JObject(
                            new JProperty("id", 1),
                            new JProperty("language", "EN"),
                            new JProperty("text", "Cats like to break iPhones, vases, cups and London magnet.")
                        )
                    )
                )
            )
        )
    );

    The results of that API call would look something like this:

    {
        "kind": "EntityRecognitionResults",
        "results": {
            "documents": [
                {
                    "id": "1",
                    "entities": [
                        {
                            "text": "iPhones",
                            "category": "Product",
                            "offset": 19,
                            "length": 7,
                            "confidenceScore": 0.99
                        },
                        {
                            "text": "vases",
                            "category": "Product",
                            "offset": 28,
                            "length": 5,
                            "confidenceScore": 0.99
                        },
                        {
                            "text": "cups",
                            "category": "Product",
                            "offset": 35,
                            "length": 4,
                            "confidenceScore": 0.99
                        },
                        {
                            "text": "London",
                            "category": "Location",
                            "subcategory": "City",
                            "offset": 44,
                            "length": 6,
                            "confidenceScore": 0.87
                        },
                        {
                            "text": "magnets",
                            "category": "Product",
                            "offset": 51,
                            "length": 7,
                            "confidenceScore": 0.54
                        }
                    ],
                    "warnings": []
                }
            ],
            "errors": [],
            "modelVersion": "2023-09-01"
        }
    }

    I created a little Azure AI Language tester in our product, so you can see Azure has some pretty powerful capabilities:

    Azure OpenAI

    I do want to add that most of our AI development has been shifting to Azure OpenAI whereby we'll ask it to extract the key information we want. It works better when customers misspell text or have confusing sentence structures. The downside is that you have to do prompt engineering to have it respond in a consistent JSON, it can take a few seconds, and there is no volume pricing. Plus it's not available in every Azure region.

    Objectively, Azure OpenAI provides better results on all text analysis tasks if you have a solid prompt. And translations are more contextually correct than standard translations. 

    We provide both options to our customers because each have their pluses and minuses. Plus we have some self-trained ones for specialized use-cases. 

    Here is an example:

    Using Azure AI - Language (example):

    Using Azure OpenAI (example):


    ------------------------------
    Maksim Gill
    Eccentex (Advanced Case and Email Management Platform for Genesys)
    https://www.eccentex.com/genesys
    ------------------------------



  • 15.  RE: Data Actions: read Information from response header / AZURE AI Language

    Posted 11-28-2023 02:15

    Hello Maksim,
    thanks for your detailed response. I was not aware of the synchronous possibilities of that API. Unfortunately my use cases involves "custom text classification" that seems to be only aviable asynchronous. But I will keep your response in mind for later usage of Language AI / openAI.

    Best regards
    Christoph



    ------------------------------
    Christoph Domaschke
    CRONBANK AG
    ------------------------------



  • 16.  RE: Data Actions: read Information from response header / AZURE AI Language

    Posted 11-29-2023 00:38

    You could always create an Azure Function between the AI service and Genesys. Genesys would call the Azure Function, which would then call the sync AI service and wait for the response before communicating it back to Genesys 



    ------------------------------
    Maksim Gill
    Eccentex (Advanced Case and Email Management Platform for Genesys)
    https://www.eccentex.com/genesys
    ------------------------------



  • 17.  RE: Data Actions: read Information from response header / AZURE AI Language

    Posted 11-29-2023 02:12

    Thanks for that idea. Actually I try to figure out Power Automate as a middleware, but AZURE itself would be next choice.



    ------------------------------
    Christoph Domaschke
    CRONBANK AG
    ------------------------------



Need Help finding something?

Check out the Genesys Knowledge Network - your all-in-one access point for Genesys resources