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

[OSS-691] fix: Externally triggered intent fail with Telegram channel #13040

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
17 changes: 11 additions & 6 deletions rasa/core/channels/telegram.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ async def send_custom_json(
class TelegramInput(InputChannel):
"""Telegram input channel."""

out_channel: TelegramOutput = None

@classmethod
def name(cls) -> Text:
return "telegram"
Expand Down Expand Up @@ -196,15 +198,15 @@ def blueprint(
self, on_new_message: Callable[[UserMessage], Awaitable[Any]]
) -> Blueprint:
telegram_webhook = Blueprint("telegram_webhook", __name__)
out_channel = self.get_output_channel()
TelegramInput.out_channel = self.get_output_channel()

@telegram_webhook.route("/", methods=["GET"])
async def health(_: Request) -> HTTPResponse:
return response.json({"status": "ok"})

@telegram_webhook.route("/set_webhook", methods=["GET", "POST"])
async def set_webhook(_: Request) -> HTTPResponse:
s = await out_channel.set_webhook(self.webhook_url)
s = await TelegramInput.out_channel.set_webhook(self.webhook_url)
if s:
logger.info("Webhook Setup Successful")
return response.text("Webhook setup successful")
Expand All @@ -220,7 +222,7 @@ async def message(request: Request) -> Any:
if isinstance(request_dict, Text):
request_dict = json.loads(request_dict)
update = Update(**request_dict)
credentials = await out_channel.get_me()
credentials = await TelegramInput.out_channel.get_me()
if not credentials.username == self.verify:
logger.debug("Invalid access token, check it matches Telegram")
return response.text("failed")
Expand Down Expand Up @@ -248,7 +250,7 @@ async def message(request: Request) -> Any:
await on_new_message(
UserMessage(
text,
out_channel,
TelegramInput.out_channel,
sender_id,
input_channel=self.name(),
metadata=metadata,
Expand All @@ -257,7 +259,7 @@ async def message(request: Request) -> Any:
await on_new_message(
UserMessage(
"/start",
out_channel,
TelegramInput.out_channel,
sender_id,
input_channel=self.name(),
metadata=metadata,
Expand All @@ -267,7 +269,7 @@ async def message(request: Request) -> Any:
await on_new_message(
UserMessage(
text,
out_channel,
TelegramInput.out_channel,
sender_id,
input_channel=self.name(),
metadata=metadata,
Expand All @@ -286,6 +288,9 @@ async def message(request: Request) -> Any:

def get_output_channel(self) -> TelegramOutput:
"""Loads the telegram channel."""
if TelegramInput.out_channel:
return TelegramInput.out_channel

channel = TelegramOutput(self.access_token)

try:
Expand Down