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

Feature: add Telegram webhook notification support #9825

Closed
wants to merge 2 commits into from

Conversation

mujahidfa
Copy link

@mujahidfa mujahidfa commented Jun 3, 2023

Adds a TelegramWebhook notification block using the AbstractAppriseNotificationBlock.

Closes #9408.

Example

from prefect.blocks.notifications import TelegramWebhook
from pydantic import SecretStr

telegram_webhook_block = TelegramWebhook(
    bot_token=SecretStr("0123456789:qwertyuiopasdfghjklzxcvbnm"), 
    chat_id="123456789"
)
telegram_webhook_block.notify("Hello from Prefect!")

Result:

Telegram chat containing 1 message from test_prefect that says 'Hello from Prefect!'.

Checklist

  • This pull request references any related issue by including "closes <link to issue>"
    • If no issue exists and your change is not a small fix, please create an issue first.
  • This pull request includes tests or only affects documentation.
  • This pull request includes a label categorizing the change e.g. fix, feature, enhancement, docs.

@mujahidfa mujahidfa requested a review from a team as a code owner June 3, 2023 06:25
@netlify
Copy link

netlify bot commented Jun 3, 2023

👷 Deploy request for prefect-docs-preview pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 0cd29c9

Copy link
Contributor

@zanieb zanieb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks for contributing!

@zanieb zanieb added the enhancement An improvement of an existing feature label Jun 3, 2023
Copy link
Member

@desertaxle desertaxle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution! The implementation looks solid! Most of my comments involve making the generated form for this block more intuitive for users. Let me know if you have any questions!

src/prefect/blocks/notifications.py Outdated Show resolved Hide resolved
Comment on lines +522 to +529
chat_id: str = Field(
description=(
"Identify the users you want your bot to deliver your notifications to. You"
" must specify at least 1 chat_id. If you do not specify a chat_id, the"
" notification script will attempt to detect the bot owner's (you) chat_id"
" and use that."
),
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on the Apprise docs, this looks like it should be a list of strings. Adding a couple of other fields will also make the generated field easier to understand.

Suggested change
chat_id: str = Field(
description=(
"Identify the users you want your bot to deliver your notifications to. You"
" must specify at least 1 chat_id. If you do not specify a chat_id, the"
" notification script will attempt to detect the bot owner's (you) chat_id"
" and use that."
),
)
chat_ids: Optional[List[str]] = Field(
default=None,
title="Chat IDs",
description=(
"The chat IDs of the users you want to deliver your notifications to. "
"If no IDs are provided, the block will attempt to detect the bot "
"owner's chat_id and use that."
),
example=["1622956968"],
)

Comment on lines +554 to +560
preview: Optional[Literal["yes", "no"]] = Field(
default=None,
description=(
"A yes/no flag allowing you to display webpage previews of your post. By"
" default this is set to no."
),
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
preview: Optional[Literal["yes", "no"]] = Field(
default=None,
description=(
"A yes/no flag allowing you to display webpage previews of your post. By"
" default this is set to no."
),
)
preview: bool = Field(
default=False,
description=(
"Whether to display webpage previews of your post."
),
)

Comment on lines +546 to +552
silent: Optional[Literal["yes", "no"]] = Field(
default=None,
description=(
"A yes/no flag allowing you to send the notification in a silent fashion."
" By default this is set to no."
),
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A bool typed field will render nicely in the UI.

Suggested change
silent: Optional[Literal["yes", "no"]] = Field(
default=None,
description=(
"A yes/no flag allowing you to send the notification in a silent fashion."
" By default this is set to no."
),
)
silent: bool = Field(
default=False,
description=(
"Whether to send the notification silently."
),
)

),
)

topic_id: Optional[SecretStr] = Field(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a sensitive value? It doesn't seem like this needs to be a SecretStr and instead could be a str.

Comment on lines +531 to +544
include_image: bool = Field(
default=False,
description=(
"You can optionally append the argument of ?image=Yes to the end of your"
" URL to have a Telegram message generated before the actual notice which"
" uploads the image associated with it. Due to the services limitations,"
" Telegram doesn't allow you to post an image inline with a text message."
" But you can send a message that just contains an image. If this flag is"
" set to true, apprise will send an image notification followed by the"
" notice itself. Since receiving 2 messages for every 1 notice could be"
" annoying to some, this has been made an option that defaults to being"
" disabled."
),
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I propose we leave this field off for now since Prefect doesn't currently handle images in notifications.

Comment on lines +584 to +592
NotifyTelegram(
bot_token=self.bot_token.get_secret_value(),
targets=self.chat_id,
include_image=self.include_image,
silent=self.silent,
preview=self.preview,
topic=self.topic_id,
detect_owner=self.detect_owner,
).url()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd be nice to include the format kwarg as well to allow different formatting styles.

Co-authored-by: Alexander Streed <desertaxle@users.noreply.github.com>
@github-actions
Copy link
Contributor

This pull request is stale because it has been open 60 days with no activity. To keep this pull request open remove stale label or comment.

@github-actions
Copy link
Contributor

This pull request was closed because it has been stale for 14 days with no activity. If this pull request is important or you have more to add feel free to re-open it.

@github-actions github-actions bot closed this Aug 26, 2023
@DhavalThkkar
Copy link

@mujahidfa @desertaxle Is there any update on this? Expected anytime soon?

@jfloodnet
Copy link

Ah that's a shame

@50Bytes-dev
Copy link
Contributor

UP!

@koolvn
Copy link

koolvn commented Oct 14, 2024

Oh, come on guys! This PR wasn't merged only because of descriptions?
Community needs the telegram notifications!

@baltic-tea
Copy link

baltic-tea commented Feb 5, 2025

UP!!!

I'd like to understand why this feature hasn't been merged yet?

Discuss: Telegram webhook notification support?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement An improvement of an existing feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature request: support Telegram webhook for notifications
9 participants