Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use the supplied auth token #5

Merged
merged 1 commit into from
Dec 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions rasa_vier_cvg/cvg.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
RESELLER_TOKEN_FIELD = "resellerToken"
PROJECT_TOKEN_FIELD = "projectToken"
CALLBACK_FIELD = "callback"
AUTH_TOKEN_FIELD = "authToken"

T = TypeVar('T')

Expand Down Expand Up @@ -66,17 +67,21 @@ class CVGOutput(OutputChannel):

on_message: Callable[[UserMessage], Awaitable[Any]]
base_url: str
headers: Dict[str, str]
proxy: Optional[str]
task_container: TaskContainer

@classmethod
def name(cls) -> Text:
return CHANNEL_NAME

def __init__(self, callback_base_url: Text, on_message: Callable[[UserMessage], Awaitable[Any]], proxy: Optional[str], task_container: TaskContainer, blocking_output: bool) -> None:
def __init__(self, callback_base_url: Text, auth_token: Text, on_message: Callable[[UserMessage], Awaitable[Any]], proxy: Optional[str], task_container: TaskContainer, blocking_output: bool) -> None:
self.on_message = on_message

self.base_url = callback_base_url.rstrip('/')
self.headers = {
"Authorization": f"Bearer {auth_token}",
}
self.proxy = proxy
self.task_container = task_container
self.blocking_output = blocking_output
Expand All @@ -96,7 +101,7 @@ async def _perform_request_sync(self, path: str, method: str, data: Optional[any
status = -1
body = None
try:
async with aiohttp.request(method, url, json=data, proxy=self.proxy) as res:
async with aiohttp.request(method, url, json=data, proxy=self.proxy, headers=self.headers) as res:
status = res.status
if status == 204:
return status, {}
Expand Down Expand Up @@ -317,9 +322,17 @@ async def _process_message(self, request: Request, on_new_message: Callable[[Use
text = text[:-1]

metadata = make_metadata(request.json)
cvg_output = CVGOutput(
request.json[CALLBACK_FIELD],
request.json[AUTH_TOKEN_FIELD],
on_new_message,
self.proxy,
self.task_container,
self.blocking_output
)
user_msg = UserMessage(
text=text,
output_channel=CVGOutput(request.json[CALLBACK_FIELD], on_new_message, self.proxy, self.task_container, self.blocking_output),
output_channel=cvg_output,
sender_id=sender_id,
input_channel=CHANNEL_NAME,
metadata=metadata,
Expand Down
Loading