-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 1. added default tabname if not exists in metadata 2. aggregated session conversation by tabname * 1. returned tabname with chat response 2. added metadata check while retrieving action name in history 3. updated razorpay action to convert amount into int and null checks * Chat server migration 1. migration to fastapi 2. added lockstore 3. unit and integration tests * fixed test failure post merge * fixed test failure post merge * fixed merge conflicts and added tests * fixed merge conflicts and added tests
- Loading branch information
1 parent
b561bc4
commit 31729f5
Showing
40 changed files
with
2,859 additions
and
2,424 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from abc import ABC | ||
|
||
|
||
class ChannelHandlerBase(ABC): | ||
|
||
async def validate(self): | ||
raise NotImplementedError("Provider not implemented") | ||
|
||
async def handle_message(self): | ||
raise NotImplementedError("Provider not implemented") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from typing import Text | ||
|
||
from kairon.chat.handlers.channels.hangouts import HangoutsHandler | ||
from kairon.chat.handlers.channels.messenger import MessengerHandler, InstagramHandler | ||
from kairon.chat.handlers.channels.msteams import MSTeamsHandler | ||
from kairon.chat.handlers.channels.slack import SlackHandler | ||
from kairon.chat.handlers.channels.telegram import TelegramHandler | ||
from kairon.chat.handlers.channels.whatsapp import WhatsappHandler | ||
from kairon.shared.constants import ChannelTypes | ||
|
||
|
||
class ChannelHandlerFactory: | ||
|
||
__implementations = { | ||
ChannelTypes.WHATSAPP.value: WhatsappHandler, | ||
ChannelTypes.HANGOUTS.value: HangoutsHandler, | ||
ChannelTypes.SLACK.value: SlackHandler, | ||
ChannelTypes.MESSENGER.value: MessengerHandler, | ||
ChannelTypes.MSTEAMS.value: MSTeamsHandler, | ||
ChannelTypes.TELEGRAM.value: TelegramHandler, | ||
ChannelTypes.INSTAGRAM.value: InstagramHandler | ||
} | ||
|
||
@staticmethod | ||
def get_handler(channel: Text): | ||
return ChannelHandlerFactory.__implementations[channel] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,12 +7,14 @@ | |
import requests | ||
from google.oauth2 import id_token | ||
from rasa.core.channels.channel import InputChannel, OutputChannel, UserMessage | ||
from tornado.escape import json_encode, json_decode | ||
from starlette.requests import Request | ||
from tornado.escape import json_encode | ||
|
||
from kairon.chat.agent_processor import AgentProcessor | ||
from kairon.chat.handlers.channels.base import ChannelHandlerBase | ||
from kairon.shared.chat.processor import ChatDataProcessor | ||
from kairon.shared.constants import ChannelTypes | ||
from kairon.shared.tornado.handlers.base import BaseHandler | ||
from kairon.shared.models import User | ||
from kairon import Utility | ||
from kairon.chat.converters.channels.response_factory import ConverterFactory | ||
|
||
|
@@ -188,7 +190,7 @@ async def send_custom_json( | |
message_type = json_message.get("type") | ||
type_list = Utility.system_metadata.get("type_list") | ||
if message_type is not None and message_type in type_list: | ||
converter_instance = ConverterFactory.getConcreteInstance(message_type, ChannelTypes.HANGOUT.value) | ||
converter_instance = ConverterFactory.getConcreteInstance(message_type, ChannelTypes.HANGOUTS.value) | ||
response = await converter_instance.messageConverter(message) | ||
await self._persist_message(response) | ||
else: | ||
|
@@ -198,7 +200,7 @@ async def send_custom_json( | |
|
||
|
||
# Google Hangouts input channel | ||
class HangoutHandler(InputChannel, BaseHandler): | ||
class HangoutsHandler(InputChannel, ChannelHandlerBase): | ||
""" | ||
Channel that uses Google Hangouts Chat API to communicate. | ||
""" | ||
|
@@ -211,6 +213,11 @@ class HangoutHandler(InputChannel, BaseHandler): | |
session=cached_session | ||
) | ||
|
||
def __init__(self, bot: Text, user: User, request: Request): | ||
self.bot = bot | ||
self.user = user | ||
self.request = request | ||
|
||
@staticmethod | ||
def _extract_sender(request_data: Dict) -> Text: | ||
|
||
|
@@ -269,14 +276,13 @@ def _check_token(self, bot_token: Text, project_id: Text) -> None: | |
if decoded_token["iss"] != "[email protected]": | ||
raise Exception(401) | ||
|
||
async def get(self, bot: str, token: str): | ||
self.write(json_encode({"status": "ok"})) | ||
async def validate(self): | ||
return {"status": "ok"} | ||
|
||
async def post(self, bot: str, token: str): | ||
user = super().authenticate_channel(token, bot, self.request) | ||
hangout = ChatDataProcessor.get_channel_config("hangouts", bot=bot, mask_characters=False) | ||
async def handle_message(self): | ||
hangout = ChatDataProcessor.get_channel_config("hangouts", bot=self.bot, mask_characters=False) | ||
project_id = hangout['config']['project_id'] | ||
request_data = json_decode(self.request.body) | ||
request_data = await self.request.json() | ||
if project_id: | ||
token = self.request.headers.get("Authorization").replace("Bearer ", "") | ||
self._check_token(token, project_id) | ||
|
@@ -285,16 +291,16 @@ async def post(self, bot: str, token: str): | |
room_name = self._extract_room(request_data) | ||
text = self._extract_message(request_data) | ||
if text is None: | ||
self.write("OK") | ||
return | ||
return {"status": "OK"} | ||
|
||
input_channel = self._extract_input_channel() | ||
|
||
collector = HangoutsOutput() | ||
|
||
try: | ||
metadata = {"is_integration_user": True, "bot": bot, "account": user.account, "room": room_name, | ||
"out_channel": collector.name(), "channel_type": "hangouts"} | ||
await AgentProcessor.get_agent(bot).handle_message(UserMessage( | ||
metadata = {"is_integration_user": True, "bot": self.bot, "account": self.user.account, "room": room_name, | ||
"out_channel": collector.name(), "channel_type": "hangouts", "tabname": "default"} | ||
await AgentProcessor.get_agent(self.bot).handle_message(UserMessage( | ||
text, | ||
collector, | ||
sender_id, | ||
|
@@ -311,5 +317,4 @@ async def post(self, bot: str, token: str): | |
f"text: {text}" | ||
) | ||
|
||
self.write(json_encode(collector.messages)) | ||
return | ||
return json_encode(collector.messages) |
Oops, something went wrong.