Conversation
* Adding support for Telegram as a Notifier * Marking messages as escaped or not * Bumping minor version due to adding new feature * Fixing linting errors
camply/notifications/telegram.py
Outdated
| response = requests.post(url=TelegramConfig.API_ENDPOINT, | ||
| headers=telegram_headers, | ||
| json=message_json) | ||
| if response.status_code != 200: |
There was a problem hiding this comment.
@stjohnjohnson one follow up question, would it be okay to raise an error here for a successful response?
There was a problem hiding this comment.
It's certainly okay to do that. I was copying how it was done for PushBullet: https://github.com/juftin/camply/blob/main/camply/notifications/pushbullet.py#L68-L69
But it seems Pushover raises an error: https://github.com/juftin/camply/blob/main/camply/notifications/pushover.py#L69-L71
There was a problem hiding this comment.
Gotcha - good catch. I made a couple very small tweaks to the notifiers. Let me know if everything looks good and we'll publish
|
Looks good to me.
On Sun, Feb 27, 2022 at 21:12 Justin Flannery ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In camply/notifications/telegram.py
<#73 (comment)>:
> +
+ Returns
+ -------
+ Response
+ """
+ if not escaped:
+ message = TelegramNotifications.escape_text(message)
+
+ telegram_headers = TelegramConfig.API_HEADERS.copy()
+ message_json = TelegramConfig.API_CONTENT.copy()
+ message_json.update({"text": message})
+ logger.debug(message_json)
+ response = requests.post(url=TelegramConfig.API_ENDPOINT,
+ headers=telegram_headers,
+ json=message_json)
+ if response.status_code != 200:
Gotcha - good catch. I made a couple very small tweaks to the notifiers.
Let me know if everything looks good and we'll publish
—
Reply to this email directly, view it on GitHub
<#73 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAEX34NCC775IIH2AJAIPK3U5L72JANCNFSM5PQBCEAQ>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
You are receiving this because you were mentioned.Message ID:
***@***.***>
--
- St. John
|
|
I'm having trouble getting Telegram notifications working. I have version camply 0.3.1 installed through pip. I'm using a Python script. I set os.environ["TELEGRAM_BOT_TOKEN"] and os.environ["TELEGRAM_CHAT_ID"]. I was confused how to get the chat id but I found this: https://codesandbox.io/s/get-telegram-chat-id-q3qkk |
Hey @Jgunde that error gets triggered by missing Environment Variables for Telegram: camply/camply/notifications/telegram.py Lines 25 to 34 in aad30dd If I were running localy (I use Linux and Mac), I would do something like this to test: export TELEGRAM_BOT_TOKEN="abcdefghijklmnop"
export TELEGRAM_CHAT_ID="1234"
camply campsites \
--rec-area 2991 \
--start-date 2022-09-10 \
--end-date 2022-09-21 \
--continuous \
--notifications telegramWhen I run that command it actually gets past the error you mentioned and throws a 404 Error (since that's a bad bot token) |
|
Also one more follow up... I didn't notice that you're using a python script. I'm not exactly sure how it works with imports and import os
import camply
os.environ["TELEGRAM_CHAT_ID"] = "fasdfahsdjfhsd"But what you want to do is set the environment variable before importing camply, or even better: set the environment variable on your system before running the python script. |
|
It worked! As you mentioned, you need to set the environmental variables BEFORE importing camply. Maybe there's a better way but I used this to find the chat id: https://codesandbox.io/s/get-telegram-chat-id-q3qkk |
Linking #72
Adding support for Telegram as a Notifier
Marking messages as escaped or not
Bumping minor version due to adding new feature
Fixing linting errors