Skip to content

Commit

Permalink
added nudge related changes and fixed test cases. (#1089)
Browse files Browse the repository at this point in the history
Co-authored-by: Mahesh <mahesh.sattala@digite.com>
  • Loading branch information
maheshsattala and Mahesh authored Dec 6, 2023
1 parent c8fdfec commit c58c168
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 0 deletions.
1 change: 1 addition & 0 deletions kairon/shared/data/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -4394,6 +4394,7 @@ def get_chat_client_config(self, bot: Text, user: Text, is_client_live: bool = F
if not client_config.config['headers'].get('X-USER'):
client_config.config['headers']['X-USER'] = user
client_config.config['api_server_host_url'] = Utility.environment['app']['server_url']
client_config.config['nudge_server_url'] = Utility.environment['nudge']['server_url']
token, refresh_token = Authentication.generate_integration_token(
bot, user, expiry=bot_settings.chat_token_expiry,
access_limit=[
Expand Down
20 changes: 20 additions & 0 deletions metadata/roles.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ roles:
modelConfiguration: true
configureClient: true
configureTelemetry: true
configureNudge: true
integrations: true
administration: true
chatHistory: true
Expand Down Expand Up @@ -56,6 +57,9 @@ roles:
configureTelemetry:
save: true
get: true
configureNudge:
save: true
get: true
integrations:
get: true
save: true
Expand Down Expand Up @@ -116,6 +120,7 @@ roles:
modelConfiguration: true
configureClient: true
configureTelemetry: true
configureNudge: true
integrations: true
administration: true
chatHistory: true
Expand Down Expand Up @@ -162,6 +167,9 @@ roles:
configureTelemetry:
save: true
get: true
configureNudge:
save: true
get: true
integrations:
get: true
save: true
Expand Down Expand Up @@ -222,6 +230,7 @@ roles:
modelConfiguration: true
configureClient: true
configureTelemetry: true
configureNudge: true
integrations: true
administration: false
chatHistory: true
Expand Down Expand Up @@ -268,6 +277,9 @@ roles:
configureTelemetry:
save: true
get: true
configureNudge:
save: true
get: true
integrations:
get: true
save: true
Expand Down Expand Up @@ -328,6 +340,7 @@ roles:
modelConfiguration: true
configureClient: true
configureTelemetry: true
configureNudge: true
integrations: false
administration: false
chatHistory: true
Expand Down Expand Up @@ -374,6 +387,9 @@ roles:
configureTelemetry:
save: false
get: true
configureNudge:
save: false
get: true
integrations:
get: false
save: false
Expand Down Expand Up @@ -434,6 +450,7 @@ roles:
modelConfiguration: false
configureClient: false
configureTelemetry: false
configureNudge: false
integrations: false
administration: false
chatHistory: false
Expand Down Expand Up @@ -480,6 +497,9 @@ roles:
configureTelemetry:
save: false
get: false
configureNudge:
save: false
get: false
integrations:
get: false
save: false
Expand Down
3 changes: 3 additions & 0 deletions system.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ data_generation:
limit_per_day: ${TRAIN_LIMIT_PER_DAY:3}
kairon_url: ${KAIRON_URL}

nudge:
server_url: ${NUDGE_SERVER_URL}

elasticsearch:
enable: ${ENABLE_APM:false}
apm_server_url: ${APM_SERVER_URL}
Expand Down
22 changes: 22 additions & 0 deletions tests/integration_test/services_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1225,6 +1225,27 @@ def test_list_pyscript_actions_after_action_deleted():
assert actual['data'][0]['dispatch_response']


def test_get_client_config_with_nudge_server_url():
expected_app_server_url = Utility.environment['app']['server_url']
expected_nudge_server_url = Utility.environment['nudge']['server_url']
expected_chat_server_url = Utility.environment['model']['agent']['url']

response = client.get(f"/api/bot/{pytest.bot}/chat/client/config",
headers={"Authorization": pytest.token_type + " " + pytest.access_token})
actual = response.json()
assert actual["success"]
assert actual["error_code"] == 0
assert actual["data"]
print(actual["data"])
assert actual["data"]["welcomeMessage"] == 'Hello! How are you?'
assert actual["data"]["name"] == 'kairon'
assert actual["data"]["buttonType"] == 'button'
assert actual["data"]["whitelist"] == ["*"]
assert actual["data"]["nudge_server_url"] == expected_nudge_server_url
assert actual["data"]["api_server_host_url"] == expected_app_server_url
assert actual["data"]["chat_server_base_url"] == expected_chat_server_url


def test_get_client_config_url_with_ip_info(monkeypatch):
monkeypatch.setitem(Utility.environment['model']['agent'], 'url', "http://localhost")
with patch("kairon.shared.plugins.ipinfo.IpInfoTracker.execute") as mock_geo_location:
Expand Down Expand Up @@ -3333,6 +3354,7 @@ def test_upload_with_chat_client_config_only():
assert actual["success"]
assert actual["error_code"] == 0
actual['data'].pop('headers')
actual['data'].pop('nudge_server_url')
assert actual["data"] == Utility.read_yaml("tests/testing_data/all/chat_client_config.yml")["config"]


Expand Down
3 changes: 3 additions & 0 deletions tests/testing_data/system.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ data_generation:
limit_per_day: ${TRAIN_LIMIT_PER_DAY:3}
kairon_url: ${KAIRON_URL}

nudge:
server_url: ${NUDGE_SERVER_URL:"http://nudgeserver"}

elasticsearch:
enable: ${ENABLE_APM:false}
apm_server_url: ${APM_SERVER_URL}
Expand Down
2 changes: 2 additions & 0 deletions tests/unit_test/data_processor/data_processor_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6360,6 +6360,8 @@ def _mock_bot_info(*args, **kwargs):
assert actual_config.config['headers']['X-USER'] == 'user@integration.com'
assert actual_config.config['api_server_host_url']
del actual_config.config['api_server_host_url']
assert actual_config.config['nudge_server_url']
del actual_config.config['nudge_server_url']
assert 'chat_server_base_url' in actual_config.config
actual_config.config.pop('chat_server_base_url')
headers = actual_config.config.pop('headers')
Expand Down

0 comments on commit c58c168

Please sign in to comment.