Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Send a Telegram message when your scripts fire an exception or when they finish their execution.

License

NotificationsYou must be signed in to change notification settings

forons/telegram-log

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Telegram-Log is a simple way to interact from multiple programming languages to a Telegram Bot.

It is released under a Apache License 2.0.

Before everything: Create the bot

Following what is writtenhere,the first step to create a bot is to start a new conversation withBotFather.With it, create a new bot with/newbot, then assign it a name and a unique username following the instructions.

TheBotFather will answer with aTOKEN, which will be needed to later use the Telegram-Log application.

Then, start a conversation with the new created bot, searching it through the global search.

Now, write/start and start a conversation.

Go tohttps://api.telegram.org/bot<TOKEN>/getUpdates (replacing<TOKEN> with the token of your bot)and you will receive a JSON that contains something like:

..."chat":{"id":123456789,"first_name":"your_name","username":"your_username",type":"private"}...

You also need the chat id in order to use the Telegram-Log application.

Now you are ready to go to the next step!

Quickstart

Java

To use the application you need to:

git clone https://github.com/forons/telegram-log.gitmvn clean install

Then, you will be able to import this project in any of your projects simply by adding in thepom.xml:

<dependency><groupId>it.forons.utils</groupId><artifactId>telegram</artifactId><version>1.0-SNAPSHOT</version></dependency>
Usage 1: Send message

As explained insrc/main/java/it/forons/utils/telegram/TelegramSender.java there two ways to send messages to a Telegram Bot:

TelegramBotbot =newTelegramBot(TOKEN,CHAT_ID);intresponseCode =bot.sendMessage("Option 1: build the class and send the message.");

or

TelegramBot.sendMessage(TOKEN,CHAT_ID,"Option 2: static method.");
Usage 2: log4j Appender

To use Telegram-Log as a log4j appender it is just needed to add the maven dependency and to set the following lines into thelog4j.properties file:

# Root logger optionlog4j.rootLogger=INFO, telegram# Direct log messages to the telegram botlog4j.appender.telegram=it.forons.utils.telegram.appender.TelegramAppenderlog4j.appender.telegram.TOKEN=<TOKEN>log4j.appender.telegram.CHAT_ID=<CHAT_ID>log4j.appender.telegram.layout=org.apache.log4j.PatternLayoutlog4j.appender.telegram.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n

Python

Just configure

TELEGRAM_TOKEN = ''TELEGRAM_CHAT_ID = ''

with yourTOKENID andCHATID, then use it as a simple Python logger:

logger = logging.getLogger('trymeApp')logger.setLevel(logging.WARNING)handler = RequestsHandler()formatter = LogstashFormatter()handler.setFormatter(formatter)logger.addHandler(handler)logger.setLevel(logging.WARNING)logger.error('We have a problem')

License

This project is licensed under the MIT License - see the LICENSE.md file for details

Acknowledgments

Marco De Nadai andPaolo Sottovia for the inspiration


Thank you to everyone who will report bugs, propose extra features, and suggest fixes.

About

Send a Telegram message when your scripts fire an exception or when they finish their execution.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp