Skip to content

Commit

Permalink
more compact sender IDs
Browse files Browse the repository at this point in the history
  • Loading branch information
pschichtel committed Nov 9, 2023
1 parent 05395c0 commit d20f972
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions rasa_vier_cvg/cvg.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,16 @@ class Recipient:

def parse_recipient_id(recipient_id: Text) -> Recipient:
parsed_json = json.loads(base64.b64decode(bytes(recipient_id, 'utf-8')).decode('utf-8'))
project_context = parsed_json["projectContext"]
return Recipient(parsed_json["dialogId"], project_context["projectToken"], project_context["resellerToken"])
return Recipient(parsed_json["dialogId"], parsed_json["projectToken"], parsed_json["resellerToken"])


def create_recipient_id(recipient: Recipient) -> Text:
json_representation = json.dumps({
"resellerToken": recipient.reseller_token,
"projectToken": recipient.project_token,
"dialogId": recipient.dialog_id,
}, separators=(',', ':'))
return base64.b64encode(bytes(json_representation, 'utf-8')).decode('utf-8')


class CVGOutput(OutputChannel):
Expand Down Expand Up @@ -267,11 +275,12 @@ async def decorated_function(request: HTTPResponse, *args, **kwargs):
return decorator(func)

async def process_message_oneline(request: Request, text: Text, must_block: bool):
sender_id_json=json.dumps({
"dialogId": request.json["dialogId"],
"projectContext": request.json["projectContext"],
})
sender_id_base64=base64.b64encode(bytes(sender_id_json, 'utf-8')).decode('utf-8')
recipient = Recipient(
request.json["projectContext"]["resellerToken"],
request.json["projectContext"]["projectToken"],
request.json["dialogId"]
)
sender_id_base64 = create_recipient_id(recipient)

result = self.process_message(
request,
Expand Down

0 comments on commit d20f972

Please sign in to comment.