Menu

Home

Krzysztof Kamil Jacewicz

Welcome to KCST Wiki!

KCST Tools

kcst-config-get

Parsing text values from config (key=value) and INI files.
Usage: kcst-config-get [-f FILENME] [-s SECTION] KEY

FILENAME specifies file to read, otherwise stdin will be read.
SECTION if specified, implies INI format. Otherwise simple KEY=VALUE format.


Examples:

  • kcst-config-get -f file.txt KEY
    reads file and prints value of a key

  • cat file.txt | kcst-config-get KEY
    reads pipe and prints value of a key

  • kcst-config-get -f file.ini -s SECTION KEY
    reads file as INI and prints value of a KEY under SECTION
  • cat file.ini | kcst-config-get -s SECTION KEY
    reads pipe as INI and prints out value of KEY under SECTION

kcst-ren-substr

batch renaming of files with rules and filters

kcst-tgbot-send

Telegram Bot client for sending messages. In order to use this tool you will need to prepare two pieces of information: a token, and a chat Id. The token belongs to a Telegram Bot and the Chat Id is a unique identifier to a chat assigned by Telegram to a specific chat conversation between the Bot and another user or group of users.

Usage: kcst-tgbot-send -t TOKEN -c CHATID [-r REPLY_ID] -m | -x | -i | -d VALUE

TOKEN specifies the token of your Telegram Bot. It can be either a directly passed token string, or an identifier prefixed with "@" symbol. When Identifier is used, the actual token will be looked up against the tgbotsend.conf file.

CHATID specifies an integer value corrsponding to a particular chat (direct or group) to which data is to be sent. You need to know this before you call the command, check telegram bot documentation for information on how to find chat Id value. This parameter can be also passed as an identifier prefixed with "@", just like the token param.

-r REPLY_ID is optional, and it indicates that the bot message will be in reply to another existing message in the chat (identified by it id).

-m MESSGE will use bot to send a passed text message to the specified chat.
-x FILENAME will load text from the specified file and send it as the message content
-i IMAGEFILE will use bot to send a passed image to the specified chat. It can be used in conjunction with -m to also send a caption.
-d DOCFILE will use bot to send a file to the chat. It can be used in conjunction with -m to also send a caption.



Configuration file is used to look up tokens and chat Ids passed to the command using identifiers (prefixed with "@" symbol). The look up will first attempt to use config at /etc/tgbotsend.conf and then at ~/tgbotsend.conf in user's home directory. The tgbotsend.conf file is in the INI format:

[tokens]
Token1={actual-token-goes-here}
[chat_id]
Chat1={actual-chat-id}
[user_id]
User1={uactual-user-id}

Note that chat_id and user_id section in the config file serve exactly same purpose, and it doesn't matter which one you use. They are mutually redundant, and only surve a purpose of organizing information in more human-readable way, so that multi-user chats can be put in one group, and direct chats between a bot and a user in another. However this usage is not enforced in any way.

Based on the sample config above, you could now make the following call:
kcst-tgbot-send -t @Token1 -c @User1 -m "Hello there!"
or:
kcst-tgbot-send -t @Token1 -c @Chat1 -m "Hello there!"

Note that multiple identifiers can resolve to the same actual value, and also that identifiers with exactly same name can exist simultaneously in the chat_id and user_id sections. The lookup will happen in the order as they appear in the config file from the top to the bottom. The first match found will take effect.


Examples:

  • kcst-tgbot-send -t @Token1 -c @Chat1 -m "Hello There!"
    Will send the message "Hello There!" to the specified chat using specified bot token. The values of -t and -c params use "@" prefix so a cofig file will be used for a look-up.

  • kcst-tgbot-send -t @Token1 -c @Chat1 -x /tmp/content.txt
    Will send the message loaded form a file at "/tmp/content.txt" to the specified chat using specified bot token. The values of -t and -c params use "@" prefix so a cofig file will be used for a look-up.

  • kcst-tgbot-send -t @Token1 -c @User1 -d /tmp/report.pdf
    Will send a pdf file into the specified chat using specified bot token. The values of -t and -c params use "@" prefix so a cofig file will be used for a look-up.
  • kcst-tgbot-send -t @Token1 -c @User1 -i /tmp/photo.jpg -m "Alert detected on CCTV camera."
    Will send an image into the specified chat using specified bot token. The values of -t and -c params use "@" prefix so a cofig file will be used for a look-up. The -m param is also used, so the image sent into the chat will also have a text caption.



The wiki uses Markdown syntax.

Project Members: