admin 管理员组

文章数量: 1086019

I am building a slack bot with an IBM Watson X Assistant. I am sending some details to IBM Watson in the context in my python code, and I am wondering how I access these values in the "Actions" section of the watsonx assistant. I have this working currently in the dialog section of watson, but I am trying to move to using just actions.

Please see code snippet below of the section of my code which sends the message from my slack bot to the assistant. The commented out section is the old code that works in the dialog version of this journey. And the new uncommented code is me trying to do similar in an action instead. I was referring to this document for the structure of this context:

I have also attached a screenshot below of the 2 watson assistants, the left being the actions only one, and the right being the one that uses dialog too. Is there another way I should be pulling these variables from the context to set in my action?

Is what I am trying to do possible? Am I doing something wrong? Or are actions more limited when it comes to this?

Thanks, Claire

watsonx action vs dialog

Here is the code snippet which I have tried:

##################################################################################
    # Message
    ##################################################################################
    response = assistant.message_stateless(
        assistant_id=ibmAssistantID,
        user_id=user_id_generated,
        # 
        input={
            'message_type': 'text',
            'text': sanitized_text,
            'options': {
                'return_context': True
            }
        },
        context={
            "skills": {
                "action skill": {  # Use "action skill" instead of "main skill"
                    "skill_variables": {
                        "slackEmailAddress": user_email,
                        "slackUserId": slack_userid,
                        "currentTimeStamp": thread_ts,
                        "slackWorkspaceEnv": slack_workspace_env
                    }
                }
            },
        # context={
        #     'skills': {
        #         'main skill': {
        #             'user_defined': {
        #                 'slackEmailAddress': user_email,
        #                 'currentTimeStamp': thread_ts,
        #                 'slackUserId': slack_userid,
        #                 'slackWorkspaceEnv': slack_workspace_env,
        #                 'cleanup_session': False  # Set a default value to 'False'
        #             }
        #         }
        #     },
            **user_context.get(user_id_generated, {})
        }
    ).get_result()

本文标签: ibm watsonIBM WatsonX AssistantAccessing Context in Actionspython Slack botStack Overflow