telegram-bot-bash/doc/6_reference.md

330 lines
7.8 KiB
Markdown
Raw Normal View History

2019-04-15 19:06:29 +00:00
## Bashbot function reference
2019-04-15 09:49:13 +00:00
### Send, forward, delete Messages
2019-04-15 10:52:38 +00:00
##### send_action
2019-04-15 17:13:39 +00:00
To send a chat action use the send_action function. Allowed values: ```typing``` for text messages, ```upload_photo``` for photos, ```record_video``` or ```upload_video``` for videos, ```record_audio``` or ```upload_audio``` for audio files, ```upload_document``` for general files, ```find_location``` for locations.
*usage:* send_action "${CHAT[ID]}" "action"
2019-04-15 09:49:13 +00:00
2019-04-15 10:52:38 +00:00
*example:*
2019-04-15 17:13:39 +00:00
```bash
send_action "${CHAT[ID]}" "typing"
send_action "${CHAT[ID]}" "record_audio"
```
2019-04-15 09:49:13 +00:00
2019-04-15 10:52:38 +00:00
##### send_normal_message
2019-04-15 19:06:29 +00:00
sen_normal_message send text only messages to chat.
*usage:* send_normal_message "${CHAT[ID]}" "message"
2019-04-15 09:49:13 +00:00
2019-04-15 10:52:38 +00:00
*example:*
2019-04-15 19:06:29 +00:00
```bash
send_normal_message "${CHAT[ID]}" "this is a text message"
```
2019-04-15 09:49:13 +00:00
2019-04-15 10:52:38 +00:00
##### send_markdown_message
2019-04-15 19:13:08 +00:00
Telegram supports only a [reduced set of Markdown](https://core.telegram.org/bots/api#markdown-style)
2019-04-15 19:06:29 +00:00
*usage:* send_markdown_message "${CHAT[ID]}" "message"
2019-04-15 10:52:38 +00:00
*example:*
2019-04-15 19:06:29 +00:00
```bash
send_normal_message "${CHAT[ID]}" "this is a markdown message, next word is *bold*"
send_normal_message "${CHAT[ID]}" "*bold* _italic_ [text](link)"
```
2019-04-15 10:52:38 +00:00
##### send_html_message
2019-04-15 19:13:08 +00:00
Telegram supports only a [reduced set of HTML](https://core.telegram.org/bots/api#html-style)
2019-04-15 19:06:29 +00:00
*usage:* send_html_message "${CHAT[ID]}" "message"
2019-04-15 10:52:38 +00:00
*example:*
2019-04-15 19:06:29 +00:00
```bash
send_normal_message "${CHAT[ID]}" "this is a markdown message, next word is <b>bold</b>"
send_normal_message "${CHAT[ID]}" "<b>bold</b> <i>italic><i> <em>italic>/em> <a href="link">Text</a>"
```
2019-04-15 10:52:38 +00:00
##### forward
2019-04-15 19:06:29 +00:00
*usage:* forward "${CHAT[ID]}" "${MESSAGE[ID]}"
2019-04-15 10:52:38 +00:00
2019-04-15 09:49:13 +00:00
----
2019-04-15 10:52:38 +00:00
##### send_message
2019-04-15 12:17:18 +00:00
Send Message must (only) used to process the output of interactive chats and background jobs.
**For your commands I reccommend the more dedicated send_xxx_message() functions above.**
2019-04-15 10:52:38 +00:00
2019-04-15 19:06:29 +00:00
*usage:* send_message "${CHAT[ID]}" "message"
2019-04-15 10:52:38 +00:00
2019-04-15 12:17:18 +00:00
*example:* - see [Usage](2_usage.md#send_message) and [Advanced Usage](3_advanced.md#Interactive-Chats)
2019-04-15 09:49:13 +00:00
----
2019-04-15 10:52:38 +00:00
##### delete_message
2019-04-15 19:06:29 +00:00
If your Bot is Admin in a Chat you can delete every message, if not you can delete only your Bot messages.
2019-04-15 10:52:38 +00:00
2019-04-15 19:06:29 +00:00
*usage:* delete_message "${CHAT[ID]}" "${MESSAGE[ID]}"
2019-04-15 09:49:13 +00:00
----
2019-04-15 10:52:38 +00:00
##### answer_inline_query
2019-04-15 19:13:08 +00:00
Inline Queries allows users to interact with your bot directly without sending extra commands.
2019-04-15 19:06:29 +00:00
answer_inline_query provide the result to a users Inline Query
2019-04-15 10:52:38 +00:00
2019-04-15 19:06:29 +00:00
*usage:* answer_inline_query "$iQUERY_ID" "type" "type arg 1" ... "type arg n"
*example:* - see [Advanced Usage](3_advanced.md#Inline-queries)
2019-04-15 09:49:13 +00:00
----
### File, Location, Venu, keyboards
2019-04-15 10:52:38 +00:00
##### get_file
*usage:*
*example:*
2019-04-15 19:06:29 +00:00
```bash
```
2019-04-15 09:49:13 +00:00
2019-04-15 10:52:38 +00:00
##### send_file
2019-04-15 19:13:08 +00:00
send_file allows you to send different type's of files, e.g. photos, stickers, audio, media, etc. [see more](https://core.telegram.org/bots/api#sending-files)
2019-04-15 19:06:29 +00:00
*usage:* send_file "${CHAT[ID]}" "file" "caption"
2019-04-15 09:49:13 +00:00
2019-04-15 10:52:38 +00:00
*example:*
2019-04-15 19:06:29 +00:00
```bash
send_file "${CHAT[ID]}" "/home/user/doge.jpg" "Lool"
send_file "${CHAT[ID]}" "https://www.domain,com/something.gif" "Something"
```
2019-04-15 09:49:13 +00:00
2019-04-15 10:52:38 +00:00
##### send_location
2019-04-15 19:06:29 +00:00
*usage:* send_location "${CHAT[ID]}" "Latitude" "Longitude"
2019-04-15 10:52:38 +00:00
##### send_venue
2019-04-15 19:06:29 +00:00
*usage:* send_venue "${CHAT[ID]}" "Latitude" "Longitude" "Title" "Address" "foursquare id (optional)"
2019-04-15 10:52:38 +00:00
2019-04-15 09:49:13 +00:00
----
2019-04-15 10:52:38 +00:00
##### send_keyboard
2019-04-16 09:46:37 +00:00
Note: since version 0.6 send_keyboard was changed to use native "JSON Array" notation as used from Telegram. Eexample Keybord Array definitions:
2019-04-15 17:13:39 +00:00
*usage:* send_keyboard "chat-id" "keyboard"
2019-04-15 10:52:38 +00:00
*example:*
2019-04-15 17:13:39 +00:00
```bash
2019-04-16 09:46:37 +00:00
send_keyboard "${CHAT[ID]}" "[ \\"yes\" , \\"no\" ]""
send_keyboard "${CHAT[ID]}" "[ \\"yes\\" ] , [ \\"no\\" ]"
send_keyboard "${CHAT[ID]}" "[ \\"1\\" , \\"2\\" , \\"3\\" ] , [ \\"4\\" , \\"5\\" , \\"6\\" ] , [ \\"7\\" , \\"8\\" , \\"9\\" ] , [ \\"0\\" ]"
2019-04-15 17:13:39 +00:00
```
2019-04-15 10:52:38 +00:00
##### remove_keyboard
*usage:*
2019-04-15 09:49:13 +00:00
### Manage users
2019-04-15 10:52:38 +00:00
##### kick_chat_member
2019-04-15 19:13:08 +00:00
If your Bot is Admin of a chat he can kick and ban a user.
2019-04-15 19:06:29 +00:00
*usage:* kick_chat_member "${CHAT[ID]}" "${USER[ID]}"
2019-04-15 09:49:13 +00:00
2019-04-15 10:52:38 +00:00
##### unban_chat_member
2019-04-15 19:13:08 +00:00
If your Bot is Admin af a chat he can unban a kicked user.
2019-04-15 10:52:38 +00:00
2019-04-15 19:06:29 +00:00
*usage:* unban_chat_member "${CHAT[ID]}" "${USER[ID]}"
2019-04-15 10:52:38 +00:00
##### leave_chat
2019-04-15 19:06:29 +00:00
Bot will leave chat.
2019-04-15 10:52:38 +00:00
2019-04-15 19:06:29 +00:00
*usage:* leave_chat "${CHAT[ID]}"
```bash
if _is_admin ; then
send_markdown_message "${CHAT[ID]}" "*LEAVING CHAT...*"
leave_chat "${CHAT[ID]}"
fi
```
2019-04-15 09:49:13 +00:00
----
2019-04-15 10:52:38 +00:00
##### user_is_creator
2019-04-15 19:06:29 +00:00
Returns true (0) if user is creator of chat or chat is a one2one / private chat.
2019-04-15 10:52:38 +00:00
2019-04-15 19:06:29 +00:00
*usage:* user_is_creator "${CHAT[ID]}" "${USER[ID]}"
*alias:* _is_creator
2019-04-15 09:49:13 +00:00
2019-04-15 10:52:38 +00:00
##### user_is_admin
2019-04-15 19:06:29 +00:00
Returns true (0) if user is admin or creator of chat.
*usage:* user_is_admin "${CHAT[ID]}" "${USER[ID]}"
*alias:* _is_creator
2019-04-15 09:49:13 +00:00
2019-04-15 10:52:38 +00:00
*example:*
2019-04-15 19:06:29 +00:00
```bash
if _is_admin ; then
send_markdown_message "${CHAT[ID]}" "*LEAVING CHAT...*"
leave_chat "${CHAT[ID]}"
fi
```
2019-04-15 09:49:13 +00:00
2019-04-15 10:52:38 +00:00
##### user_is_botadmin
2019-04-15 19:06:29 +00:00
Returns true (0) if user is owner / admin of bot.
botadmin is stored in file './botadmin'
*usage:* user_is_botadmin "${CHAT[ID]}" "${USER[ID]}"
*alias:* _is_botadmin
2019-04-15 10:52:38 +00:00
*example:*
2019-04-15 19:06:29 +00:00
```bash
_is_botadmin && send_markdown_message "${CHAT[ID]}" "You are *BOTADMIN*."
```
2019-04-15 10:52:38 +00:00
##### user_is_allowed
2019-04-15 19:06:29 +00:00
Bahsbot supports User Access Control, see [Advanced Usage](4_advanced.ma)
*usage:* user_is_allowed "${USER[ID]}" "what" "${CHAT[ID]}"
2019-04-15 10:52:38 +00:00
*example:*
2019-04-15 19:06:29 +00:00
```bash
if ! user_is_allowed "${USER[ID]}" "start" "${CHAT[ID]}" ; then
send_normal_message "${CHAT[ID]}" "You are not allowed to start Bot."
fi
```
2019-04-15 09:49:13 +00:00
### Interactive and backgound jobs
2019-04-15 10:52:38 +00:00
##### startproc
2019-04-15 19:06:29 +00:00
With ```startproc``` you can start scrips (or C or python program etc.). The text that the script will output will be sent in real time to the user, and all user input will be sent to the script. see [Advanced Usage](3_advanced.md#Interactive-Chats)
*usage:* startproc "./script"
2019-04-15 10:52:38 +00:00
*example:*
2019-04-15 19:06:29 +00:00
```bash
startproc './calc'
```
2019-04-15 10:52:38 +00:00
##### checkproc
2019-04-15 19:06:29 +00:00
Returns true (0) if an interactive script is running in chat.
*usage:* checkprog
2019-04-15 09:49:13 +00:00
2019-04-15 10:52:38 +00:00
*example:*
2019-04-15 19:06:29 +00:00
```bash
checkproc
if [ "$res" -gt 0 ] ; then
startproc "./calc"
else
send_normal_message "${CHAT[ID]}" "Calc already running ..."
fi
```
2019-04-15 09:49:13 +00:00
2019-04-15 10:52:38 +00:00
##### killproc
2019-04-15 19:06:29 +00:00
*usage:* killproc
2019-04-15 10:52:38 +00:00
*example:*
2019-04-15 19:06:29 +00:00
```bash
checkprog
if [ "$res" -eq 0 ]; then
killproc && send_message "${CHAT[ID]}" "Command canceled."
else
send_message "${CHAT[ID]}" "Command is not running."
fi
```
2019-04-15 09:49:13 +00:00
----
2019-04-15 10:52:38 +00:00
##### background
2019-04-15 19:06:29 +00:00
*usage:* background "./script" "jobname"
2019-04-15 10:52:38 +00:00
*example:*
2019-04-15 19:06:29 +00:00
```bash
background "./notify" "notify"
```
2019-04-15 10:52:38 +00:00
##### checkback
2019-04-15 19:06:29 +00:00
Returns true (0) if an background job is running in chat.
*usage:* checkback "jobname"
2019-04-15 10:52:38 +00:00
*example:*
2019-04-15 19:06:29 +00:00
```bash
checkback "notify"
if [ "$res" -gt 0 ] ; then
send_normal_message "${CHAT[ID]}" "Start notify"
background "./notify" "notify"
else
send_normal_message "${CHAT[ID]}" "Process notify already running."
fi
```
2019-04-15 09:49:13 +00:00
2019-04-15 10:52:38 +00:00
##### killback
2019-04-15 19:06:29 +00:00
*usage:* killback "jobname"
2019-04-15 09:49:13 +00:00
2019-04-15 10:52:38 +00:00
*example:*
2019-04-15 19:06:29 +00:00
```bash
checkback "notify"
if [ "$res" -eq 0 ] ; then
send_normal_message "${CHAT[ID]}" "Kill notify"
killback "notify"
else
send_normal_message "${CHAT[ID]}" "Process notify not run."
fi
```
2019-04-15 09:49:13 +00:00
### Bashbot internal
2019-04-15 12:17:18 +00:00
These functions are for internal use only and must not used in your bot commands.
2019-04-15 09:49:13 +00:00
2019-04-15 10:52:38 +00:00
##### send_text
2019-04-15 19:06:29 +00:00
*usage:* send_text "${CHAT[ID]}" "message"
2019-04-15 10:52:38 +00:00
2019-04-15 09:49:13 +00:00
----
2019-04-15 10:52:38 +00:00
##### JsonDecode
2019-04-15 19:06:29 +00:00
Outputs decoded string to STDOUT
*usage:* JsonDecode "string"
2019-04-15 10:52:38 +00:00
##### JsonGetString
2019-04-15 19:06:29 +00:00
Reads JSON fro STDIN and Outputs found String to STDOUT
*usage:* JsonGetString `"path","to","string"`
2019-04-15 09:49:13 +00:00
2019-04-15 10:52:38 +00:00
##### JsonGetValue
2019-04-15 19:06:29 +00:00
Reads JSON fro STDIN and Outputs found Value to STDOUT
*usage:* JsonGetValue `"path","to","value"`
2019-04-15 10:52:38 +00:00
2019-04-15 09:49:13 +00:00
----
2019-04-15 10:52:38 +00:00
##### get_chat_member_status
2019-04-15 19:06:29 +00:00
*usage:* get_chat_member_status "${CHAT[ID]}" "${USER[ID]}"
2019-04-15 10:52:38 +00:00
2019-04-15 09:49:13 +00:00
----
2019-04-15 10:52:38 +00:00
##### process_client
2019-04-15 12:17:18 +00:00
Every Message sent to your Bot is processd by this function. It parse the send JSON and assign the found Values to bash variables.
2019-04-15 10:52:38 +00:00
##### process_updates
2019-04-15 12:17:18 +00:00
If new updates are availible, this functions gets the JSON from Telegram and dispatch it.
2019-04-15 09:49:13 +00:00
----
2019-04-15 10:52:38 +00:00
##### getBotName
2019-04-15 12:17:18 +00:00
The name of your bot is availible as bash variable "$ME", there is no need to call this function if Bot is running.
2019-04-15 10:52:38 +00:00
2019-04-15 12:17:18 +00:00
*usage:* ME="$(getBotNiname)"
2019-04-15 10:52:38 +00:00
##### inproc
2019-04-15 12:17:18 +00:00
Send Input from Telegram to waiting Interactive Chat.
2019-04-15 09:49:13 +00:00
2019-04-16 09:46:37 +00:00
#### $$VERSION$$ v0.60-rc2-2-g7727608
2019-04-15 09:49:13 +00:00