OpenNyAI / Jugalbandi-Manager

Jugalbandi (JB) Manager is a full AI-powered conversational chatbot platform. It's platform agnostic and can serve multiple channels such as WhatsApp or custom web interfaces. It can handle conversations in both text and voice across any language. It comes with Bhashini Speech models out of the box and can failover to Azure.
https://opennyai.github.io/Jugalbandi-Manager/
Apache License 2.0
15 stars 12 forks source link

[Bug]: WA_API_HOST needs to be added to the JB Manager UI Config #31

Open kanak8278 opened 1 month ago

kanak8278 commented 1 month ago

Describe the bug

Currently WA_API_HOST need to be mentioned in the .env-dev, move it to JB Manager UI, along with the other Whatsapp configs.

Steps to reproduce

No response

Expected Behavior

No response

Screenshots and logs

No response

Additional Information

No response

sameersegal commented 1 month ago

We need to store API_HOST as well. Until now we were only storing API_KEY against the channel type/name. For e.g. the channel settings for a given bot were stored as follows:

{
  "whatsapp": "xlslkdfslkdfjslfd"
}

This needs to move to:

{
 "whatsapp": {
     "key": "xlslkdfslkdfjslfd",
     "host": "https://api.whatsapp.com"
  }
}

Phone number also is channel specific. However, we can't make that change immediately because JBBot's primary key is phone number. This needs to be done in a separate issue/PR.

Given that JBBot data model is Column(JSON). We don't need to change it. It can accommodate the change in structure that we want. However, the values need to be flushed out i.e. we need to add a step for alembic migration to delete all the bots.

We will stick to this naming convention. key, host

Lib Layer

Every helper in the lib/whatsapp.py (https://github.com/OpenNyAI/Jugalbandi-Manager/blob/main/lib/whatsapp.py) needs to take API host along with wa_api_key. Change to match naming convention.

Channel Layer

WA_API_HOST needs to come from bot_channel_credentials (https://github.com/OpenNyAI/Jugalbandi-Manager/blob/2c522e3bd578444d420082e89ba4e5d7b446534a/channel/src/__main__.py#L178 ). Change naming convention.

API Layer

/bot/{id}/activate for whatsapp needs to also store a host. See https://github.com/OpenNyAI/Jugalbandi-Manager/blob/2c522e3bd578444d420082e89ba4e5d7b446534a/api/app/main.py#L139

Also we need to encrypt a nested dict https://github.com/OpenNyAI/Jugalbandi-Manager/blob/2c522e3bd578444d420082e89ba4e5d7b446534a/api/app/main.py#L168C16-L168C28

Frontend:

Add api_host for Whatsapp https://github.com/OpenNyAI/Jugalbandi-Manager/blob/2c522e3bd578444d420082e89ba4e5d7b446534a/frontend/src/components/project/project.tsx#L57

Add validation for capture api_host https://github.com/OpenNyAI/Jugalbandi-Manager/blob/2c522e3bd578444d420082e89ba4e5d7b446534a/frontend/src/components/settings-model/index.tsx#L62

data['channels']['whatsapp'] = inputElements['whatsapp'].value;

this data structure needs to change because we not only need to store API_KEY but also API_HOST (potentially others)

data['channels'][] = str ---> dictionary

sameersegal commented 1 month ago

@shreypandey the PR you have linked to doesn't solve the issue across all the layers. Please see the comment carefully. This change needs to be implemented across Frontend layer as well. The #21 doesn't seem to touch Frontend and it's not clear that it's has addressed all the points in API, Channel, and Lib layers

shreypandey commented 1 month ago

@sameersegal The PR #21 contains the changes for custom channel implementation which implicitly addresses the issue of storing API host along API key for different channels for each bot.

21 is still under WIP due to frontend changes and JBManager flow refactoring fixes shreypandey/JB-Manager#7 .