langgenius / dify

Dify is an open-source LLM app development platform. Dify's intuitive interface combines AI workflow, RAG pipeline, agent capabilities, model management, observability features and more, letting you quickly go from prototype to production.
https://dify.ai
Other
46.02k stars 6.49k forks source link

wecom_group_bot, return not a valid UUID #7374

Closed yshaoliang closed 3 weeks ago

yshaoliang commented 1 month ago

Self Checks

Dify version

0.7.0

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

Integrate wecom_group-bot, send message returns invalid UUID

✔️ Expected Behavior

{"wecom_group_bot": {"content": "This is a test msg.", "hook_key": "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=27ff0100-1d2a-4293-xxxx-3b9b44477a68", "message_type": "text"}}

❌ Actual Behavior

{"wecom_group_bot": "Invalid parameter hook_key $https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=27ff0100-1d2a-4293-xxxx-3b9b44477a68, not a valid UUID"}

dosubot[bot] commented 1 month ago

@yshaoliang Hello! I'm here to help you with bugs, questions, and becoming a contributor. Let's squash those bugs together! 😄

The invalid UUID error when integrating wecom_group-bot and sending a message in Dify version 0.7.0 when self-hosted with Docker is likely due to incorrect configuration of the environment variables in the docker-compose.yml file. Specifically, ensure that the DIFY_API_BASE, DIFY_API_KEY, and DIFY_APP_TYPE environment variables are correctly set.

Here is the relevant section from the documentation:

version: '2.0'
services:
  dify-on-wechat:
    image: hanfangyuan/dify-on-wechat
    container_name: dify-on-wechat
    security_opt:
      - seccomp:unconfined
    environment:
      DIFY_API_BASE: 'https://api.dify.ai/v1'
      DIFY_API_KEY: 'app-xx'
      DIFY_APP_TYPE: 'chatbot'
      MODEL: 'dify'
      SINGLE_CHAT_PREFIX: '[""]'
      SINGLE_CHAT_REPLY_PREFIX: '""'
      GROUP_CHAT_PREFIX: '["@bot"]'
      GROUP_NAME_WHITE_LIST: '["ALL_GROUP"]'

Ensure that the DIFY_API_KEY is a valid key and the DIFY_API_BASE is correctly set to your API server address [1].

Additionally, the hook_key parameter in the wecom_group_bot integration must be a valid UUID. The error message indicates that the provided hook_key is not recognized as a valid UUID. Here is a code snippet that shows the validation:

if not is_valid_uuid(hook_key):
    return self.create_text_message(
        f'Invalid parameter hook_key ${hook_key}, not a valid UUID')

Make sure that the hook_key you are using is a valid UUID [2][3].

Dify also has a specific error handling mechanism for parsing UUIDs in the WorkflowAppService class. The _safe_parse_uuid method is used to safely parse a string into a UUID. If the string is shorter than 32 characters or cannot be parsed into a valid UUID, the method returns None:

@staticmethod
def _safe_parse_uuid(value: str):
    # fast check
    if len(value) < 32:
        return None

    try:
        return uuid.UUID(value)
    except ValueError:
        return None

This method provides a detailed check to determine if a UUID is valid and logs the reason why a UUID might be considered invalid (either due to length or parsing error) [4].

To continue talking to Dosu, mention @dosu.

yshaoliang commented 1 month ago

@yshaoliang Hello! I'm here to help you with bugs, questions, and becoming a contributor. Let's squash those bugs together! 😄

The invalid UUID error when integrating wecom_group-bot and sending a message in Dify version 0.7.0 when self-hosted with Docker is likely due to incorrect configuration of the environment variables in the docker-compose.yml file. Specifically, ensure that the DIFY_API_BASE, DIFY_API_KEY, and DIFY_APP_TYPE environment variables are correctly set.

Here is the relevant section from the documentation:

version: '2.0'
services:
  dify-on-wechat:
    image: hanfangyuan/dify-on-wechat
    container_name: dify-on-wechat
    security_opt:
      - seccomp:unconfined
    environment:
      DIFY_API_BASE: 'https://api.dify.ai/v1'
      DIFY_API_KEY: 'app-xx'
      DIFY_APP_TYPE: 'chatbot'
      MODEL: 'dify'
      SINGLE_CHAT_PREFIX: '[""]'
      SINGLE_CHAT_REPLY_PREFIX: '""'
      GROUP_CHAT_PREFIX: '["@bot"]'
      GROUP_NAME_WHITE_LIST: '["ALL_GROUP"]'

Ensure that the DIFY_API_KEY is a valid key and the DIFY_API_BASE is correctly set to your API server address [1].

Additionally, the hook_key parameter in the wecom_group_bot integration must be a valid UUID. The error message indicates that the provided hook_key is not recognized as a valid UUID. Here is a code snippet that shows the validation:

if not is_valid_uuid(hook_key):
    return self.create_text_message(
        f'Invalid parameter hook_key ${hook_key}, not a valid UUID')

Make sure that the hook_key you are using is a valid UUID [2][3].

Dify also has a specific error handling mechanism for parsing UUIDs in the WorkflowAppService class. The _safe_parse_uuid method is used to safely parse a string into a UUID. If the string is shorter than 32 characters or cannot be parsed into a valid UUID, the method returns None:

@staticmethod
def _safe_parse_uuid(value: str):
    # fast check
    if len(value) < 32:
        return None

    try:
        return uuid.UUID(value)
    except ValueError:
        return None

This method provides a detailed check to determine if a UUID is valid and logs the reason why a UUID might be considered invalid (either due to length or parsing error) [4].

To continue talking to Dosu, mention @dosu.

Thanks for your help! I have configured YAML according to your instructions and ensured that DIFY_API_BASE and DIFY_API_KEY are correct: DIFY_API_BASE: ' http://localhost/v1 ' DIFY_API_KEY: 'app-r5WC7hymNwOYuMH8plvfAbA6'

And I also ensure that this UUID is copied from the wecom group chat robot app: https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=27ff0100-1d2a-4293-****-3b9b44477a68

Restart Docker, log in to dify again, but still return an invalid UUID

11

dosubot[bot] commented 1 month ago

It seems like the wecom_group_bot is still returning an invalid UUID error despite your configurations. Here are a few things to double-check:

  1. UUID Validation: Ensure that the hook_key you are using is a valid UUID. The error message indicates that the provided hook_key is not recognized as a valid UUID. The validation code snippet is as follows:

    if not is_valid_uuid(hook_key):
        return self.create_text_message(
            f'Invalid parameter hook_key ${hook_key}, not a valid UUID')

    Make sure the hook_key you copied from the WeCom group chat robot app is correctly formatted as a UUID.

  2. Configuration File: Verify that your config.json file in the project root directory is correctly set up. Here is an example configuration:

    {
      "dify_api_base": "https://api.dify.ai/v1",
      "dify_api_key": "app-xxx",
      "dify_app_type": "chatbot",
      "channel_type": "wx",
      "model": "dify",
      "single_chat_prefix": [""],
      "single_chat_reply_prefix": "",
      "group_chat_prefix": ["@bot"],
      "group_name_white_list": ["ALL_GROUP"]
    }

    Ensure that the dify_api_key and dify_api_base match the settings from your Dify application.

If everything seems correct and the issue persists, it might be helpful to get additional assistance. @takatost, could you take a look at this issue?

To continue talking to Dosu, mention @dosu.

yshaoliang commented 1 month ago

@yshaoliang Hello! I'm here to help you with bugs, questions, and becoming a contributor. Let's squash those bugs together! 😄

The invalid UUID error when integrating wecom_group-bot and sending a message in Dify version 0.7.0 when self-hosted with Docker is likely due to incorrect configuration of the environment variables in the docker-compose.yml file. Specifically, ensure that the DIFY_API_BASE, DIFY_API_KEY, and DIFY_APP_TYPE environment variables are correctly set.

Here is the relevant section from the documentation:

version: '2.0'
services:
  dify-on-wechat:
    image: hanfangyuan/dify-on-wechat
    container_name: dify-on-wechat
    security_opt:
      - seccomp:unconfined
    environment:
      DIFY_API_BASE: 'https://api.dify.ai/v1'
      DIFY_API_KEY: 'app-xx'
      DIFY_APP_TYPE: 'chatbot'
      MODEL: 'dify'
      SINGLE_CHAT_PREFIX: '[""]'
      SINGLE_CHAT_REPLY_PREFIX: '""'
      GROUP_CHAT_PREFIX: '["@bot"]'
      GROUP_NAME_WHITE_LIST: '["ALL_GROUP"]'

Ensure that the DIFY_API_KEY is a valid key and the DIFY_API_BASE is correctly set to your API server address [1].

Additionally, the hook_key parameter in the wecom_group_bot integration must be a valid UUID. The error message indicates that the provided hook_key is not recognized as a valid UUID. Here is a code snippet that shows the validation:

if not is_valid_uuid(hook_key):
    return self.create_text_message(
        f'Invalid parameter hook_key ${hook_key}, not a valid UUID')

Make sure that the hook_key you are using is a valid UUID [2][3].

Dify also has a specific error handling mechanism for parsing UUIDs in the WorkflowAppService class. The _safe_parse_uuid method is used to safely parse a string into a UUID. If the string is shorter than 32 characters or cannot be parsed into a valid UUID, the method returns None:

@staticmethod
def _safe_parse_uuid(value: str):
    # fast check
    if len(value) < 32:
        return None

    try:
        return uuid.UUID(value)
    except ValueError:
        return None

This method provides a detailed check to determine if a UUID is valid and logs the reason why a UUID might be considered invalid (either due to length or parsing error) [4].

To continue talking to Dosu, mention @dosu.

It seems like the wecom_group_bot is still returning an invalid UUID error despite your configurations. Here are a few things to double-check:

  1. UUID Validation: Ensure that the hook_key you are using is a valid UUID. The error message indicates that the provided hook_key is not recognized as a valid UUID. The validation code snippet is as follows:

    if not is_valid_uuid(hook_key):
       return self.create_text_message(
           f'Invalid parameter hook_key ${hook_key}, not a valid UUID')

    Make sure the hook_key you copied from the WeCom group chat robot app is correctly formatted as a UUID.

  2. Configuration File: Verify that your config.json file in the project root directory is correctly set up. Here is an example configuration:

    {
     "dify_api_base": "https://api.dify.ai/v1",
     "dify_api_key": "app-xxx",
     "dify_app_type": "chatbot",
     "channel_type": "wx",
     "model": "dify",
     "single_chat_prefix": [""],
     "single_chat_reply_prefix": "",
     "group_chat_prefix": ["@bot"],
     "group_name_white_list": ["ALL_GROUP"]
    }

    Ensure that the dify_api_key and dify_api_base match the settings from your Dify application.

If everything seems correct and the issue persists, it might be helpful to get additional assistance. @takatost, could you take a look at this issue?

To continue talking to Dosu, mention @dosu.

Thank you for your prompt reply!

The UUID is "27ff0100-1d2a-4293-****-3b9b44477a68", and its format and content are correct. I added channel_type="wx" in the yaml file.

I restarted Docker, but the problem still persists. Have you personally tested it?

oiuv commented 1 month ago

I have the same error, and I'm sure my hook_key is correct.


That's strange, the test is working normally now. Suggestion

image