mirror of
https://github.com/octoleo/telegram-bot-bash.git
synced 2024-12-28 20:52:36 +00:00
create html doc for dist
This commit is contained in:
parent
b831e60cbe
commit
5269b54aec
@ -1,7 +1,7 @@
|
||||
#!/usr/bin/env bash
|
||||
# this has to run once atfer git clone
|
||||
# and every time we create new hooks
|
||||
#### $$VERSION$$ v0.70-pre1-0-g490c472
|
||||
#### $$VERSION$$ v0.70-pre1-9-gb831e60
|
||||
|
||||
# magic to ensure that we're always inside the root of our application,
|
||||
# no matter from which directory we'll run script
|
||||
@ -24,7 +24,7 @@ do
|
||||
fi
|
||||
done
|
||||
|
||||
# create dir for sitribution and copy files
|
||||
# create dir for distribution and copy files
|
||||
mkdir -p "${DISTDIR}" 2>/dev/null
|
||||
# shellcheck disable=SC2086
|
||||
cp -r ${DISTFILES} "${DISTDIR}"
|
||||
@ -41,6 +41,12 @@ if [ ! -f "${JSONSHFILE}" ]; then
|
||||
chmod +x "${JSONSHFILE}"
|
||||
fi
|
||||
|
||||
# make html doc
|
||||
mkdir html
|
||||
cp README.html html/index.html
|
||||
find ./doc -iname "*.md" -type f -exec sh -c 'pandoc -s -S -M "title=Bashobot Documentation - ${0%.md}.html" "${0}" -o "./html/$(basename ${0%.md}.html)"' {} \;
|
||||
find README.html html -iname "*.html" -type f -exec sh -c 'sed -i -E "s/href=\"(.*).md\"/href=\"\1.html\"/g" ${0}' {} \;
|
||||
|
||||
# create archive
|
||||
cd .. || exit 1
|
||||
zip -rq "${DISTNAME}-${VERSION}.zip" "${DISTNAME}"
|
||||
|
76
html/0_install.html
Normal file
76
html/0_install.html
Normal file
@ -0,0 +1,76 @@
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<meta http-equiv="Content-Style-Type" content="text/css" />
|
||||
<meta name="generator" content="pandoc" />
|
||||
<title>Bashobot Documentation - 0_install.html</title>
|
||||
<style type="text/css">code{white-space: pre;}</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="header">
|
||||
<h1 class="title">Bashobot Documentation - 0_install.html</h1>
|
||||
</div>
|
||||
<h4 id="home"><a href="../README.html">Home</a></h4>
|
||||
<h2 id="install-bashbot">Install bashbot</h2>
|
||||
<ol style="list-style-type: decimal">
|
||||
<li>Go to the directory you want to install bashbot, e.g.
|
||||
<ul>
|
||||
<li>your $HOME directory (install and run with your user-ID)</li>
|
||||
<li>/usr/local if you want to run as service</li>
|
||||
</ul></li>
|
||||
<li><a href="https://github.com/topkecleon/telegram-bot-bash/releases">Download latest release zip from github</a> and extract all files.</li>
|
||||
<li>Change into the directory <code>telegram-bot-bash</code></li>
|
||||
<li>Create default commands with <code>cp commands.sh.dist commands.sh; cp mycommands.sh.dist mycommands.sh</code></li>
|
||||
<li>Run <code>./bashbot.sh init</code> to setup the environment and enter your Bots token given by botfather.</li>
|
||||
</ol>
|
||||
<p>Now your Bot is ready to start …</p>
|
||||
<p><strong>If you are new to Bot development read <a href="https://core.telegram.org/bots">Bots: An introduction for developers</a></strong></p>
|
||||
<h3 id="install-from-github">Install from Github</h3>
|
||||
<p>As an alternative to download the zip files, you can clone the github repository to get the latest improvements/fixes.</p>
|
||||
<ol style="list-style-type: decimal">
|
||||
<li>Go to the directory you want to install bashbot, e.g.
|
||||
<ul>
|
||||
<li>your $HOME directory (install and run with your user-ID)</li>
|
||||
<li>/usr/local if you want to run as service</li>
|
||||
</ul></li>
|
||||
<li>Run <code>git clone https://github.com/topkecleon/telegram-bot-bash.git</code></li>
|
||||
<li>Change into the directory <code>telegram-bot-bash</code></li>
|
||||
<li>Run <code>test/ALL-tests.sh</code> and if everthing finish OK …</li>
|
||||
<li>Run <code>sudo ./bashbot.sh init</code> to setup the environment and enter your Bots token given by botfather.</li>
|
||||
</ol>
|
||||
<h3 id="update-bashbot">Update bashbot</h3>
|
||||
<ol style="list-style-type: decimal">
|
||||
<li>Go to the directory where you had installed bashbot, e.g.
|
||||
<ul>
|
||||
<li>your $HOME directory</li>
|
||||
<li>/usr/local</li>
|
||||
</ul></li>
|
||||
<li><a href="https://github.com/topkecleon/telegram-bot-bash/releases">Download latest release zip from github</a></li>
|
||||
<li>Extract all files to your existing bashbot dir <strong>Note: all files execpt ‘mycommands.sh’ and ‘commands.sh’ may overwritten!</strong></li>
|
||||
<li>Run <code>sudo ./bashbot.sh init</code> to setup your environment after the update</li>
|
||||
</ol>
|
||||
<h3 id="notes-on-updates">Notes on Updates</h3>
|
||||
<h4 id="location-of-tmp-data-dir">Location of tmp / data dir</h4>
|
||||
<p>From version 0.70 on the tmp dir is renamed to ‘data-bot-bash’ to reflect the fact that not only temporary files are stored. an existing ‘tmp-bot-bash’ will be automatically renamed after update.</p>
|
||||
<p>From version 0.50 on the temporary files are no more placed in ‘/tmp’. instead a dedicated tmp dir is used.</p>
|
||||
<h4 id="changes-to-send_keyboard-in-v0.6">Changes to send_keyboard in v0.6</h4>
|
||||
<p>From Version 0.60 on keybord format for <code>send_keyboard</code> and <code>send_message "mykeyboardstartshere ..."</code> was changed. Keybords are now defined in JSON Array notation e.g. “[ \“yes\” , \“no\” ]”. This has the advantage that you can create any type of keyboard supported by Telegram. The old format is supported for backward compatibility, but may fail for corner cases.</p>
|
||||
<p><em>Example Keyboards</em>:</p>
|
||||
<ul>
|
||||
<li>yes no in two rows:
|
||||
<ul>
|
||||
<li>OLD format: ‘yes’ ‘no’ <em>(two strings)</em></li>
|
||||
<li>NEW format: ‘[ “yes” ] , [ “no” ]’ <em>(two arrays with a string)</em></li>
|
||||
</ul></li>
|
||||
<li>new layouts made easy with NEW format:
|
||||
<ul>
|
||||
<li>Yes No in one row: ‘[ “yes” , “no” ]’</li>
|
||||
<li>Yes No plus Maybe in 2.row: ‘[ “yes” , “no” ] , [ “maybe” ]’</li>
|
||||
<li>numpad style keyboard: ‘[ “1” , “2” , “3” ] , [ “4” , “5” , “6” ] , [ “7” , “8” , “9” ] , [ “0” ]’</li>
|
||||
</ul></li>
|
||||
</ul>
|
||||
<h4 id="next-create-bot"><a href="1_firstbot.html">Next Create Bot</a></h4>
|
||||
<h4 id="version-v0.70-pre1-2-g293ad08"><br /><span class="math display"><em>V</em><em>E</em><em>R</em><em>S</em><em>I</em><em>O</em><em>N</em></span><br /> v0.70-pre1-2-g293ad08</h4>
|
||||
</body>
|
||||
</html>
|
53
html/1_firstbot.html
Normal file
53
html/1_firstbot.html
Normal file
@ -0,0 +1,53 @@
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<meta http-equiv="Content-Style-Type" content="text/css" />
|
||||
<meta name="generator" content="pandoc" />
|
||||
<title>Bashobot Documentation - 1_firstbot.html</title>
|
||||
<style type="text/css">code{white-space: pre;}</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="header">
|
||||
<h1 class="title">Bashobot Documentation - 1_firstbot.html</h1>
|
||||
</div>
|
||||
<h4 id="home"><a href="../README.html">Home</a></h4>
|
||||
<h2 id="create-a-telegram-bot-with-botfather">Create a Telegram Bot with botfather</h2>
|
||||
<p><strong><a href="https://core.telegram.org/bots#3-how-do-i-create-a-bot">BotFather is the one bot to rule them all</a>. It will help you create new bots and change settings for existing ones.</strong> <a href="https://core.telegram.org/bots#generating-an-authorization-token">Commands known by Botfather</a></p>
|
||||
<h3 id="creating-a-new-bot">Creating a new Bot</h3>
|
||||
<ol style="list-style-type: decimal">
|
||||
<li>Message <span class="citation">@botfather</span> https://telegram.me/botfather with the following text: <code>/newbot</code> If you don’t know how to message by username, click the search field on your Telegram app and type <code>@botfather</code>, you should be able to initiate a conversation. Be careful not to send it to the wrong contact, because some users has similar usernames to <code>botfather</code>.</li>
|
||||
</ol>
|
||||
<div class="figure">
|
||||
<img src="http://i.imgur.com/aI26ixR.png" alt="botfather initial conversation" />
|
||||
<p class="caption">botfather initial conversation</p>
|
||||
</div>
|
||||
<ol start="2" style="list-style-type: decimal">
|
||||
<li><p><span class="citation">@botfather</span> replies with <code>Alright, a new bot. How are we going to call it? Please choose a name for your bot.</code></p></li>
|
||||
<li><p>Type whatever name you want for your bot.</p></li>
|
||||
<li><p><span class="citation">@botfather</span> replies with <code>Good. Now let's choose a username for your bot. It must end in bot. Like this, for example: TetrisBot or tetris_bot.</code></p></li>
|
||||
<li><p>Type whatever username you want for your bot, minimum 5 characters, and must end with <code>bot</code>. For example: <code>telesample_bot</code></p></li>
|
||||
<li><p><span class="citation">@botfather</span> replies with:</p>
|
||||
<p>Done! Congratulations on your new bot. You will find it at telegram.me/telesample_bot. You can now add a description, about section and profile picture for your bot, see /help for a list of commands.</p>
|
||||
<p>Use this token to access the HTTP API: <b>123456789:AAG90e14-0f8-40183D-18491dDE</b></p>
|
||||
<p>For a description of the Bot API, see this page: https://core.telegram.org/bots/api</p></li>
|
||||
<li><p>Note down the ‘token’ mentioned above.</p></li>
|
||||
<li><p>Type <code>/setprivacy</code> to <span class="citation">@botfather</span>.</p></li>
|
||||
</ol>
|
||||
<div class="figure">
|
||||
<img src="http://i.imgur.com/tWDVvh4.png" alt="botfather later conversation" />
|
||||
<p class="caption">botfather later conversation</p>
|
||||
</div>
|
||||
<ol start="9" style="list-style-type: decimal">
|
||||
<li><p><span class="citation">@botfather</span> replies with <code>Choose a bot to change group messages settings.</code></p></li>
|
||||
<li><p>Type <code>@telesample_bot</code> (change to the username you set at step 5 above, but start it with <code>@</code>)</p></li>
|
||||
<li><p><span class="citation">@botfather</span> replies with</p>
|
||||
<p>‘Enable’ - your bot will only receive messages that either start with the ‘/’ symbol or mention the bot by username. ‘Disable’ - your bot will receive all messages that people send to groups. Current status is: ENABLED</p></li>
|
||||
<li><p>Type <code>Disable</code> to let your bot receive all messages sent to a group. This step is up to you actually.</p></li>
|
||||
<li><p><span class="citation">@botfather</span> replies with <code>Success! The new status is: DISABLED. /help</code></p></li>
|
||||
</ol>
|
||||
<h4 id="prev-installation"><a href="0_install.html">Prev Installation</a></h4>
|
||||
<h4 id="next-getting-started"><a href="2_usage.html">Next Getting started</a></h4>
|
||||
<h4 id="version-v0.70-pre1-2-g293ad08"><br /><span class="math display"><em>V</em><em>E</em><em>R</em><em>S</em><em>I</em><em>O</em><em>N</em></span><br /> v0.70-pre1-2-g293ad08</h4>
|
||||
</body>
|
||||
</html>
|
179
html/2_usage.html
Normal file
179
html/2_usage.html
Normal file
@ -0,0 +1,179 @@
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<meta http-equiv="Content-Style-Type" content="text/css" />
|
||||
<meta name="generator" content="pandoc" />
|
||||
<title>Bashobot Documentation - 2_usage.html</title>
|
||||
<style type="text/css">code{white-space: pre;}</style>
|
||||
<style type="text/css">
|
||||
div.sourceCode { overflow-x: auto; }
|
||||
table.sourceCode, tr.sourceCode, td.lineNumbers, td.sourceCode {
|
||||
margin: 0; padding: 0; vertical-align: baseline; border: none; }
|
||||
table.sourceCode { width: 100%; line-height: 100%; }
|
||||
td.lineNumbers { text-align: right; padding-right: 4px; padding-left: 4px; color: #aaaaaa; border-right: 1px solid #aaaaaa; }
|
||||
td.sourceCode { padding-left: 5px; }
|
||||
code > span.kw { color: #007020; font-weight: bold; } /* Keyword */
|
||||
code > span.dt { color: #902000; } /* DataType */
|
||||
code > span.dv { color: #40a070; } /* DecVal */
|
||||
code > span.bn { color: #40a070; } /* BaseN */
|
||||
code > span.fl { color: #40a070; } /* Float */
|
||||
code > span.ch { color: #4070a0; } /* Char */
|
||||
code > span.st { color: #4070a0; } /* String */
|
||||
code > span.co { color: #60a0b0; font-style: italic; } /* Comment */
|
||||
code > span.ot { color: #007020; } /* Other */
|
||||
code > span.al { color: #ff0000; font-weight: bold; } /* Alert */
|
||||
code > span.fu { color: #06287e; } /* Function */
|
||||
code > span.er { color: #ff0000; font-weight: bold; } /* Error */
|
||||
code > span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warning */
|
||||
code > span.cn { color: #880000; } /* Constant */
|
||||
code > span.sc { color: #4070a0; } /* SpecialChar */
|
||||
code > span.vs { color: #4070a0; } /* VerbatimString */
|
||||
code > span.ss { color: #bb6688; } /* SpecialString */
|
||||
code > span.im { } /* Import */
|
||||
code > span.va { color: #19177c; } /* Variable */
|
||||
code > span.cf { color: #007020; font-weight: bold; } /* ControlFlow */
|
||||
code > span.op { color: #666666; } /* Operator */
|
||||
code > span.bu { } /* BuiltIn */
|
||||
code > span.ex { } /* Extension */
|
||||
code > span.pp { color: #bc7a00; } /* Preprocessor */
|
||||
code > span.at { color: #7d9029; } /* Attribute */
|
||||
code > span.do { color: #ba2121; font-style: italic; } /* Documentation */
|
||||
code > span.an { color: #60a0b0; font-weight: bold; font-style: italic; } /* Annotation */
|
||||
code > span.cv { color: #60a0b0; font-weight: bold; font-style: italic; } /* CommentVar */
|
||||
code > span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Information */
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="header">
|
||||
<h1 class="title">Bashobot Documentation - 2_usage.html</h1>
|
||||
</div>
|
||||
<h4 id="home"><a href="../README.html">Home</a></h4>
|
||||
<h2 id="gettting-started">Gettting Started</h2>
|
||||
<p>The Bots standard commands are in <code>commands.sh</code> file. You must not add your commands to ‘commands.sh’, instead place them in <code>mycommands.sh</code>, there you also find examples how to process messages and send out text. See <a href="5_practice.html">Best practices</a> for more information.</p>
|
||||
<p>Once you’re done with editing ‘mycommands.sh’ start the Bot with <code>./bashbot.sh start</code>. If some thing doesn’t work as it should, debug with <code>bash -x bashbot.sh</code>. To stop the Bot run <code>./bashbot.sh kill</code></p>
|
||||
<p>To use the functions provided in this script in other scripts simply source bashbot: <code>source bashbot.sh</code></p>
|
||||
<p>Have FUN!</p>
|
||||
<h2 id="managing-your-own-bot">Managing your own Bot</h2>
|
||||
<h4 id="note-running-bashbot-as-root-is-highly-danger-and-not-recommended.-see-expert-use.">Note: running bashbot as root is highly danger and not recommended. See Expert use.</h4>
|
||||
<h3 id="start-stop">Start / Stop</h3>
|
||||
<p>Start or Stop your Bot use the following commands:</p>
|
||||
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="ex">./bashbot.sh</span> start</code></pre></div>
|
||||
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="ex">./bashbot.sh</span> kill</code></pre></div>
|
||||
<h3 id="user-count">User count</h3>
|
||||
<p>To count the total number of users that ever used the bot run the following command:</p>
|
||||
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="ex">./bashbot.sh</span> count</code></pre></div>
|
||||
<h3 id="sending-broadcasts-to-all-users">Sending broadcasts to all users</h3>
|
||||
<p>To send a broadcast to all of users that ever used the bot run the following command:</p>
|
||||
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="ex">./bashbot.sh</span> broadcast <span class="st">"Hey! I just wanted to let you know that the bot's been updated!"</span></code></pre></div>
|
||||
<h2 id="recieve-data">Recieve data</h2>
|
||||
<p>Evertime a Message is recieved, you can read incoming data using the following variables:</p>
|
||||
<ul>
|
||||
<li><code>${MESSAGE}</code>: Current message</li>
|
||||
<li><code>${MESSAGE[ID]}</code>: ID of current message</li>
|
||||
<li><code>$CAPTION</code>: Captions</li>
|
||||
<li><code>$REPLYTO</code>: Original message wich was replied to</li>
|
||||
<li><code>$USER</code>: This array contains the First name, last name, username and user id of the sender of the current message.
|
||||
<ul>
|
||||
<li><code>${USER[ID]}</code>: User id</li>
|
||||
<li><code>${USER[FIRST_NAME]}</code>: User’s first name</li>
|
||||
<li><code>${USER[LAST_NAME]}</code>: User’s last name</li>
|
||||
<li><code>${USER[USERNAME]}</code>: Username</li>
|
||||
</ul></li>
|
||||
<li><code>$CHAT</code>: This array contains the First name, last name, username, title and user id of the chat of the current message.
|
||||
<ul>
|
||||
<li><code>${CHAT[ID]}</code>: Chat id</li>
|
||||
<li><code>${CHAT[FIRST_NAME]}</code>: Chat’s first name</li>
|
||||
<li><code>${CHAT[LAST_NAME]}</code>: Chat’s last name</li>
|
||||
<li><code>${CHAT[USERNAME]}</code>: Username</li>
|
||||
<li><code>${CHAT[TITLE]}</code>: Title</li>
|
||||
<li><code>${CHAT[TYPE]}</code>: Type</li>
|
||||
<li><code>${CHAT[ALL_MEMBERS_ARE_ADMINISTRATORS]}</code>: All members are administrators (true if true)</li>
|
||||
</ul></li>
|
||||
<li><code>$REPLYTO</code>: This array contains the First name, last name, username and user id of the ORIGINAL sender of the message REPLIED to.
|
||||
<ul>
|
||||
<li><code>${REPLYTO[ID]}</code>: ID of message wich was replied to</li>
|
||||
<li><code>${REPLYTO[UID]}</code>: Original user’s id</li>
|
||||
<li><code>${REPLYTO[FIRST_NAME]}</code>: Original user’s first name</li>
|
||||
<li><code>${REPLYTO[LAST_NAME]}</code>: Original user’s’ last name</li>
|
||||
<li><code>${REPLYTO[USERNAME]}</code>: Original user’s username</li>
|
||||
</ul></li>
|
||||
<li><code>$FORWARD</code>: This array contains the First name, last name, username and user id of the ORIGINAL sender of the FORWARDED message.
|
||||
<ul>
|
||||
<li><code>${FORWARD[ID]}</code>: Same as MESSAGE[ID] if message is forwarded</li>
|
||||
<li><code>${FORWARD[UID]}</code>: Original user’s id</li>
|
||||
<li><code>${FORWARD[FIRST_NAME]}</code>: Original user’s first name</li>
|
||||
<li><code>${FORWARD[LAST_NAME]}</code>: Original user’s’ last name</li>
|
||||
<li><code>${FORWARD[USERNAME]}</code>: Original user’s username</li>
|
||||
</ul></li>
|
||||
<li><code>$URLS</code>: This array contains documents, audio files, voice recordings and stickers as URL.
|
||||
<ul>
|
||||
<li><code>${URLS[AUDIO]}</code>: Audio files</li>
|
||||
<li><code>${URLS[VIDEO]}</code>: Videos</li>
|
||||
<li><code>${URLS[PHOTO]}</code>: Photos (maximum quality)</li>
|
||||
<li><code>${URLS[VOICE]}</code>: Voice recordings</li>
|
||||
<li><code>${URLS[STICKER]}</code>: Stickers</li>
|
||||
<li><code>${URLS[DOCUMENT]}</code>: Any other file</li>
|
||||
</ul></li>
|
||||
<li><code>$CONTACT</code>: This array contains info about contacts sent in a chat.
|
||||
<ul>
|
||||
<li><code>${CONTACT[ID]}</code>: User id</li>
|
||||
<li><code>${CONTACT[NUMBER]}</code>: Phone number</li>
|
||||
<li><code>${CONTACT[FIRST_NAME]}</code>: First name</li>
|
||||
<li><code>${CONTACT[LAST_NAME]}</code>: Last name</li>
|
||||
<li><code>${CONTACT[VCARD]}</code>: User’s complete Vcard</li>
|
||||
</ul></li>
|
||||
<li><code>$LOCATION</code>: This array contains info about locations sent in a chat.
|
||||
<ul>
|
||||
<li><code>${LOCATION[LONGITUDE]}</code>: Longitude</li>
|
||||
<li><code>${LOCATION[LATITUDE]}</code>: Latitude</li>
|
||||
</ul></li>
|
||||
<li><code>$VENUE</code>: This array contains info about venue (a place) sent in a chat.
|
||||
<ul>
|
||||
<li><code>${VENUE[TITLE]}</code>: Name of the place</li>
|
||||
<li><code>${VENUE[ADDRESS]}</code>: Address of the place</li>
|
||||
<li><code>${VENUE[LONGITUDE]}</code>: Longitude</li>
|
||||
<li><code>${VENUE[LATITUDE]}</code>: Latitude</li>
|
||||
<li><code>${VENUE[FOURSQUARE]}</code>: Fouresquare ID</li>
|
||||
</ul></li>
|
||||
</ul>
|
||||
<h2 id="usage-of-bashbot-functions">Usage of bashbot functions</h2>
|
||||
<h4 id="sending-messages">sending messages</h4>
|
||||
<p>To send messages use the <code>send_xxx_message</code> functions.</p>
|
||||
<p>To send regular text without any markdown use:</p>
|
||||
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="ex">send_text_message</span> <span class="st">"</span><span class="va">${CHAT[ID]}</span><span class="st">"</span> <span class="st">"lol"</span></code></pre></div>
|
||||
<p>To send text with markdown:</p>
|
||||
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="ex">send_markdown_message</span> <span class="st">"</span><span class="va">${CHAT[ID]}</span><span class="st">"</span> <span class="st">"lol *bold*"</span></code></pre></div>
|
||||
<p>To send text with html:</p>
|
||||
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="ex">send_html_message</span> <span class="st">"</span><span class="va">${CHAT[ID]}</span><span class="st">"</span> <span class="st">"lol <b>bold</b>"</span></code></pre></div>
|
||||
<p>To forward messages use the <code>forward</code> function:</p>
|
||||
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="ex">forward</span> <span class="st">"</span><span class="va">${CHAT[ID]}</span><span class="st">"</span> <span class="st">"from_chat_id"</span> <span class="st">"message_id"</span></code></pre></div>
|
||||
<p>If your Bot is Admin in a Chat you can delete every message, if not you can delete only your messages. To delete a message with a known <span class="math inline">${MESSAGE[ID]} you can simple use: ```bash delete_message "$</span>{CHAT[ID]}" “${MESSAGE[ID]}” ```</p>
|
||||
<h4 id="send_message">send_message</h4>
|
||||
<p>In addition there is a universal send_massage function which can output any type of message. This function is used to process output from external scrips like interactive chats or background jobs.<br />
|
||||
<strong>For safety and performance reasons I recommend to use send_xxxx_message functions above for sending messages</strong></p>
|
||||
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="ex">send_message</span> <span class="st">"</span><span class="va">${CHAT[ID]}</span><span class="st">"</span> <span class="st">"lol"</span></code></pre></div>
|
||||
<p>To send html or markdown put the following strings before the text, depending on the parsing mode you want to enable:</p>
|
||||
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="ex">send_message</span> <span class="st">"</span><span class="va">${CHAT[ID]}</span><span class="st">"</span> <span class="st">"markdown_parse_mode lol *bold*"</span></code></pre></div>
|
||||
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="ex">send_message</span> <span class="st">"</span><span class="va">${CHAT[ID]}</span><span class="st">"</span> <span class="st">"html_parse_mode lol <b>bold</b>"</span></code></pre></div>
|
||||
<p>This function also allows a third parameter that disables additional function parsing (for safety use this when reprinting user input):</p>
|
||||
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="ex">send_message</span> <span class="st">"</span><span class="va">${CHAT[ID]}</span><span class="st">"</span> <span class="st">"lol"</span> <span class="st">"safe"</span></code></pre></div>
|
||||
<p><strong>See also <a href="3_advanced.md#Interactive-Chats">Interactive chats</a></strong></p>
|
||||
<h4 id="send-files-locations-keyboards.">Send files, locations, keyboards.</h4>
|
||||
<p>To send images, videos, voice files, photos etc. use the <code>send_photo</code> function (remember to change the safety Regex @ line 14 of command.sh to allow sending files only from certain directories):</p>
|
||||
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="ex">send_file</span> <span class="st">"</span><span class="va">${CHAT[ID]}</span><span class="st">"</span> <span class="st">"/home/user/doge.jpg"</span> <span class="st">"Lool"</span></code></pre></div>
|
||||
<p>To send custom keyboards use the <code>send_keyboard</code> function:</p>
|
||||
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="ex">send_keyboard</span> <span class="st">"</span><span class="va">${CHAT[ID]}</span><span class="st">"</span> <span class="st">"Text that will appear in chat?"</span> <span class="st">'[ "Yep" , "No" ]'</span> <span class="co"># note the simgle quotes!</span>
|
||||
<span class="ex">send_keyboard</span> <span class="st">"</span><span class="va">${CHAT[ID]}</span><span class="st">"</span> <span class="st">"Text that will appear in chat?"</span> <span class="st">"[ </span><span class="dt">\\</span><span class="st">"</span>Yep<span class="dt">\\</span><span class="st">" , </span><span class="dt">\\</span><span class="st">"</span>No<span class="dt">\\</span><span class="st">" ]"</span> <span class="co"># within double quotes you must excape the inside double quots</span></code></pre></div>
|
||||
<p>To send locations use the <code>send_location</code> function:</p>
|
||||
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="ex">send_location</span> <span class="st">"</span><span class="va">${CHAT[ID]}</span><span class="st">"</span> <span class="st">"Latitude"</span> <span class="st">"Longitude"</span></code></pre></div>
|
||||
<p>To send venues use the <code>send_venue</code> function:</p>
|
||||
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="ex">send_venue</span> <span class="st">"</span><span class="va">${CHAT[ID]}</span><span class="st">"</span> <span class="st">"Latitude"</span> <span class="st">"Longitude"</span> <span class="st">"Title"</span> <span class="st">"Address"</span> <span class="st">"optional foursquare id"</span></code></pre></div>
|
||||
<p>To send a chat action use the <code>send_action</code> 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.</p>
|
||||
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="ex">send_action</span> <span class="st">"</span><span class="va">${CHAT[ID]}</span><span class="st">"</span> <span class="st">"action"</span></code></pre></div>
|
||||
<p><strong>See also <a href="6_reference.md#Interactive_Chats">Bashbot function reference</a></strong></p>
|
||||
<h4 id="prev-create-bot"><a href="1_firstbot.html">Prev Create Bot</a></h4>
|
||||
<h4 id="next-advanced-usage"><a href="3_advanced.html">Next Advanced Usage</a></h4>
|
||||
<h4 id="version-v0.70-pre1-2-g293ad08"><br /><span class="math display"><em>V</em><em>E</em><em>R</em><em>S</em><em>I</em><em>O</em><em>N</em></span><br /> v0.70-pre1-2-g293ad08</h4>
|
||||
</body>
|
||||
</html>
|
161
html/3_advanced.html
Normal file
161
html/3_advanced.html
Normal file
@ -0,0 +1,161 @@
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<meta http-equiv="Content-Style-Type" content="text/css" />
|
||||
<meta name="generator" content="pandoc" />
|
||||
<title>Bashobot Documentation - 3_advanced.html</title>
|
||||
<style type="text/css">code{white-space: pre;}</style>
|
||||
<style type="text/css">
|
||||
div.sourceCode { overflow-x: auto; }
|
||||
table.sourceCode, tr.sourceCode, td.lineNumbers, td.sourceCode {
|
||||
margin: 0; padding: 0; vertical-align: baseline; border: none; }
|
||||
table.sourceCode { width: 100%; line-height: 100%; }
|
||||
td.lineNumbers { text-align: right; padding-right: 4px; padding-left: 4px; color: #aaaaaa; border-right: 1px solid #aaaaaa; }
|
||||
td.sourceCode { padding-left: 5px; }
|
||||
code > span.kw { color: #007020; font-weight: bold; } /* Keyword */
|
||||
code > span.dt { color: #902000; } /* DataType */
|
||||
code > span.dv { color: #40a070; } /* DecVal */
|
||||
code > span.bn { color: #40a070; } /* BaseN */
|
||||
code > span.fl { color: #40a070; } /* Float */
|
||||
code > span.ch { color: #4070a0; } /* Char */
|
||||
code > span.st { color: #4070a0; } /* String */
|
||||
code > span.co { color: #60a0b0; font-style: italic; } /* Comment */
|
||||
code > span.ot { color: #007020; } /* Other */
|
||||
code > span.al { color: #ff0000; font-weight: bold; } /* Alert */
|
||||
code > span.fu { color: #06287e; } /* Function */
|
||||
code > span.er { color: #ff0000; font-weight: bold; } /* Error */
|
||||
code > span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warning */
|
||||
code > span.cn { color: #880000; } /* Constant */
|
||||
code > span.sc { color: #4070a0; } /* SpecialChar */
|
||||
code > span.vs { color: #4070a0; } /* VerbatimString */
|
||||
code > span.ss { color: #bb6688; } /* SpecialString */
|
||||
code > span.im { } /* Import */
|
||||
code > span.va { color: #19177c; } /* Variable */
|
||||
code > span.cf { color: #007020; font-weight: bold; } /* ControlFlow */
|
||||
code > span.op { color: #666666; } /* Operator */
|
||||
code > span.bu { } /* BuiltIn */
|
||||
code > span.ex { } /* Extension */
|
||||
code > span.pp { color: #bc7a00; } /* Preprocessor */
|
||||
code > span.at { color: #7d9029; } /* Attribute */
|
||||
code > span.do { color: #ba2121; font-style: italic; } /* Documentation */
|
||||
code > span.an { color: #60a0b0; font-weight: bold; font-style: italic; } /* Annotation */
|
||||
code > span.cv { color: #60a0b0; font-weight: bold; font-style: italic; } /* CommentVar */
|
||||
code > span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Information */
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="header">
|
||||
<h1 class="title">Bashobot Documentation - 3_advanced.html</h1>
|
||||
</div>
|
||||
<h4 id="home"><a href="../README.html">Home</a></h4>
|
||||
<h2 id="advanced-features">Advanced Features</h2>
|
||||
<h3 id="access-control">Access control</h3>
|
||||
<p>Bashbot offers functions to check what Telegram capabilities like ‘chat admin’ or ‘chat creator’ the given user has:</p>
|
||||
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="co"># return true if user is admin/owner of the bot</span>
|
||||
<span class="co"># -> botadmin is stored in file './botadmin'</span>
|
||||
<span class="ex">user_is_botadmin</span> <span class="st">"user"</span>
|
||||
|
||||
<span class="co"># return true if user is creator or admin of a chat</span>
|
||||
<span class="ex">user_is_admin</span> <span class="st">"chat"</span> <span class="st">"user"</span>
|
||||
|
||||
<span class="co"># return true if user is creator of a chat or it's a one to one chat</span>
|
||||
<span class="ex">user_is_creator</span> <span class="st">"chat"</span> <span class="st">"user"</span>
|
||||
|
||||
<span class="co"># examples:</span>
|
||||
<span class="ex">user_is_botadmin</span> <span class="st">"</span><span class="va">${USER[ID]}</span><span class="st">"</span> <span class="kw">&&</span> <span class="ex">send_markdown_message</span> <span class="st">"</span><span class="va">${CHAT[ID]}</span><span class="st">"</span> <span class="st">"You are *BOTADMIN*."</span>
|
||||
|
||||
<span class="ex">user_is_admin</span> <span class="st">"</span><span class="va">${CHAT[ID]}</span><span class="st">"</span> <span class="st">"</span><span class="va">${USER[ID]}</span><span class="st">"</span> <span class="kw">&&</span> <span class="ex">send_markdown_message</span> <span class="st">"</span><span class="va">${CHAT[ID]}</span><span class="st">"</span> <span class="st">"You are *CHATADMIN*."</span></code></pre></div>
|
||||
<p>In addition you can check individual capabilities of users as you must define in the file <code>./botacl</code>:</p>
|
||||
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="co"># file: botacl</span>
|
||||
<span class="co"># a user not listed here, will return false from 'user_is_allowed'</span>
|
||||
<span class="co">#</span>
|
||||
<span class="co"># Format:</span>
|
||||
<span class="co"># user:ressource:chat</span>
|
||||
|
||||
<span class="co"># allow user 123456789 access to all resources in all chats</span>
|
||||
<span class="ex">123456789</span>:*:*
|
||||
|
||||
<span class="co"># allow user 12131415 to start bot in all chats</span>
|
||||
<span class="ex">12131415</span>:start:*
|
||||
|
||||
<span class="co"># allow user 987654321 only to start bot in chat 98979695</span>
|
||||
<span class="ex">987654321</span>:start:98979695
|
||||
|
||||
<span class="co"># * are only allowed on the right hand side and not for user!</span>
|
||||
<span class="co"># the following exaples are NOT valid!</span>
|
||||
<span class="ex">*</span>:*:*
|
||||
<span class="ex">*</span>:start:*
|
||||
<span class="ex">*</span>:*:98979695</code></pre></div>
|
||||
<p>You must use the function <code>user_is_allowed</code> to check if a user has the capability to do something. Example: Check if user has capability to start bot.</p>
|
||||
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"> <span class="kw">case</span> <span class="st">"</span><span class="va">$MESSAGE</span><span class="st">"</span><span class="kw"> in</span>
|
||||
<span class="co">################################################</span>
|
||||
<span class="co"># GLOBAL commands start here, only edit messages</span>
|
||||
<span class="st">'/start'</span>*<span class="kw">)</span>
|
||||
<span class="ex">user_is_botadmin</span> <span class="st">"</span><span class="va">${USER[ID]}</span><span class="st">"</span> <span class="kw">&&</span> <span class="ex">send_markdown_message</span> <span class="st">"</span><span class="va">${CHAT[ID]}</span><span class="st">"</span> <span class="st">"You are *BOTADMIN*."</span>
|
||||
<span class="kw">if</span> <span class="ex">user_is_allowed</span> <span class="st">"</span><span class="va">${USER[ID]}</span><span class="st">"</span> <span class="st">"start"</span> <span class="st">"</span><span class="va">${CHAT[ID]}</span><span class="st">"</span> <span class="kw">;</span> <span class="kw">then</span>
|
||||
<span class="ex">bot_help</span> <span class="st">"</span><span class="va">${CHAT[ID]}</span><span class="st">"</span>
|
||||
<span class="kw">else</span>
|
||||
<span class="ex">send_normal_message</span> <span class="st">"</span><span class="va">${CHAT[ID]}</span><span class="st">"</span> <span class="st">"You are not allowed to start Bot."</span>
|
||||
<span class="kw">;;</span>
|
||||
<span class="kw">esac</span></code></pre></div>
|
||||
<p><strong>See also <a href="6_reference.md#User-Access-Control">Bashbot User Access Control functions</a></strong></p>
|
||||
<h3 id="interactive-chats">Interactive Chats</h3>
|
||||
<p>To create interactive chats, write <em>(or edit the ‘exmaples/question.sh’ script)</em> a bash <em>(or C or python)</em> script, make it executable and then use the ‘startproc’ function to start the script. The output of the script will be sent to the user and user input will be sent to the script. To stop the script use the function ‘killprog’</p>
|
||||
<p>The output of the script will be processed by ‘send_messages’ to enable you to not only send text, but also keyboards, files, locations and more. Each newline in the output will start an new message to the user, to have line breaks in your message you can use ‘mynewlinestartshere’.</p>
|
||||
<p>To open up a keyboard in an interactive script, print out the keyboard layout in the following way:</p>
|
||||
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="bu">echo</span> <span class="st">"Text that will appear in chat? mykeyboardstartshere [ </span><span class="dt">\"</span><span class="st">Yep, sure</span><span class="dt">\"</span><span class="st"> , </span><span class="dt">\"</span><span class="st">No, highly unlikely</span><span class="dt">\"</span><span class="st"> ]"</span></code></pre></div>
|
||||
<p>Same goes for files:</p>
|
||||
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="bu">echo</span> <span class="st">"Text that will appear in chat? myfilelocationstartshere /home/user/doge.jpg"</span></code></pre></div>
|
||||
<p>And buttons:</p>
|
||||
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="bu">echo</span> <span class="st">"Text that will appear in chat. mybtextstartshere Klick me myburlstartshere https://dealz.rrr.de"</span></code></pre></div>
|
||||
<p>And locations:</p>
|
||||
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="bu">echo</span> <span class="st">"Text that will appear in chat. mylatstartshere 45 mylongstartshere 45"</span></code></pre></div>
|
||||
<p>And venues:</p>
|
||||
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="bu">echo</span> <span class="st">"Text that will appear in chat. mylatstartshere 45 mylongstartshere 45 mytitlestartshere my home myaddressstartshere Diagon Alley N. 37"</span></code></pre></div>
|
||||
<p>You can combine them:</p>
|
||||
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="bu">echo</span> <span class="st">"Text that will appear in chat? mykeyboardstartshere [ </span><span class="dt">\"</span><span class="st">Yep, sure</span><span class="dt">\"</span><span class="st"> , </span><span class="dt">\"</span><span class="st">No, highly unlikely</span><span class="dt">\"</span><span class="st"> ] myfilelocationstartshere /home/user/doge.jpg mylatstartshere 45 mylongstartshere 45"</span></code></pre></div>
|
||||
<p>Please note that you can either send a location or a venue, not both. To send a venue add the mytitlestartshere and the myaddressstartshere keywords.</p>
|
||||
<p>New in v0.6: To insert a linebreak in your message you can insert <code>mynewlinestartshere</code> in your echo command:</p>
|
||||
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="bu">echo</span> <span class="st">"Text that will appear in one message mynewlinestartshere with this text on a new line"</span></code></pre></div>
|
||||
<p>New in v0.7: In case you must extend a message already containing a location, a file, a keyboard etc., with additionial text simply add <code>mytextstartshere additional text</code> at the end of the string:</p>
|
||||
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="va">out=</span><span class="st">"Text that will appear mylatstartshere 45 mylongstartshere 45"</span>
|
||||
<span class="kw">[[</span> <span class="st">"</span><span class="va">$out</span><span class="st">"</span> <span class="ot">!=</span> *<span class="st">'in chat'</span>*<span class="kw"> ]]</span> <span class="kw">&&</span> <span class="va">out=</span><span class="st">"</span><span class="va">$out</span><span class="st"> mytextstartshere in chat."</span>
|
||||
<span class="bu">echo</span> <span class="st">"</span><span class="va">$out</span><span class="st">"</span></code></pre></div>
|
||||
<p>Note: Interactive Chats run independent from main bot and continue running until your script exits or you /cancel if from your Bot.</p>
|
||||
<h3 id="background-jobs">Background Jobs</h3>
|
||||
<p>A background job is similar to an interactive chat, but runs in the background and does only output massages and does not get user input. In contrast to interactive chats it’s possible to run multiple background jobs. To create a background job write a script or edit ‘examples/notify.sh’ script and use the funtion <code>background</code> to start it:</p>
|
||||
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="ex">background</span> <span class="st">"examples/notify.sh"</span> <span class="st">"jobname"</span></code></pre></div>
|
||||
<p>All output of the script will be sent to the user, to stop a background job use:</p>
|
||||
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="ex">killback</span> <span class="st">"jobname"</span></code></pre></div>
|
||||
<p>You can also suspend and resume the last running background jobs from outside bashbot, e.g. in your startup schripts:</p>
|
||||
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="ex">./bashbot.sh</span> suspendback
|
||||
<span class="ex">./bashbot.sh</span> resumeback</code></pre></div>
|
||||
<p>If you want to kill all background jobs permantly run:</p>
|
||||
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="ex">./bashbot.sh</span> killback</code></pre></div>
|
||||
<p>Note: Background Jobs run independent from main bot and continue running until your script exits or you stop if from your Bot. Backgound Jobs will continue running if your Bot is stopeda and must be terminated, e.g. by <code>bashbot.sh killback</code></p>
|
||||
<h3 id="inline-queries">Inline queries</h3>
|
||||
<p>The following commands allows users to interact with your bot via <em>inline queries</em>. In order to enable <strong>inline mode</strong>, send <code>/setinline</code> command to <span class="citation">[@BotFather]</span>(https://telegram.me/botfather) and provide the placeholder text that the user will see in the input field after typing your bot’s name. Also, edit line 12 from <code>commands.sh</code> putting a “1”. Note that you can’t modify the first two parameters of the function <code>answer_inline_query</code>, only the ones after them.</p>
|
||||
<p>To send messsages or links through an <em>inline query</em>:</p>
|
||||
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="ex">answer_inline_query</span> <span class="st">"</span><span class="va">$iQUERY_ID</span><span class="st">"</span> <span class="st">"article"</span> <span class="st">"Title of the result"</span> <span class="st">"Content of the message to be sent"</span></code></pre></div>
|
||||
<p>To send photos in jpeg format and less than 5MB, from a website through an <em>inline query</em>:</p>
|
||||
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="ex">answer_inline_query</span> <span class="st">"</span><span class="va">$iQUERY_ID</span><span class="st">"</span> <span class="st">"photo"</span> <span class="st">"A valid URL of the photo"</span> <span class="st">"URL of the thumbnail"</span></code></pre></div>
|
||||
<p>To send standard gifs from a website (less than 1MB) through an <em>inline query</em>:</p>
|
||||
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="ex">answer_inline_query</span> <span class="st">"</span><span class="va">$iQUERY_ID</span><span class="st">"</span> <span class="st">"gif"</span> <span class="st">"gif url"</span></code></pre></div>
|
||||
<p>To send mpeg4 gifs from a website (less than 1MB) through an <em>inline query</em>:</p>
|
||||
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="ex">answer_inline_query</span> <span class="st">"</span><span class="va">$iQUERY_ID</span><span class="st">"</span> <span class="st">"mpeg4_gif"</span> <span class="st">"mpeg4 gif url"</span></code></pre></div>
|
||||
<p>To send videos from a website through an <em>inline query</em>:</p>
|
||||
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="ex">answer_inline_query</span> <span class="st">"</span><span class="va">$iQUERY_ID</span><span class="st">"</span> <span class="st">"video"</span> <span class="st">"valid video url"</span> <span class="st">"Select one mime type: text/html or video/mp4"</span> <span class="st">"URL of the thumbnail"</span> <span class="st">"Title for the result"</span></code></pre></div>
|
||||
<p>To send photos stored in Telegram servers through an <em>inline query</em>:</p>
|
||||
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="ex">answer_inline_query</span> <span class="st">"</span><span class="va">$iQUERY_ID</span><span class="st">"</span> <span class="st">"cached_photo"</span> <span class="st">"identifier for the photo"</span></code></pre></div>
|
||||
<p>To send gifs stored in Telegram servers through an <em>inline query</em>:</p>
|
||||
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="ex">answer_inline_query</span> <span class="st">"</span><span class="va">$iQUERY_ID</span><span class="st">"</span> <span class="st">"cached_gif"</span> <span class="st">"identifier for the gif"</span></code></pre></div>
|
||||
<p>To send mpeg4 gifs stored in Telegram servers through an <em>inline query</em>:</p>
|
||||
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="ex">answer_inline_query</span> <span class="st">"</span><span class="va">$iQUERY_ID</span><span class="st">"</span> <span class="st">"cached_mpeg4_gif"</span> <span class="st">"identifier for the gif"</span></code></pre></div>
|
||||
<p>To send stickers through an <em>inline query</em>:</p>
|
||||
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="ex">answer_inline_query</span> <span class="st">"</span><span class="va">$iQUERY_ID</span><span class="st">"</span> <span class="st">"cached_sticker"</span> <span class="st">"identifier for the sticker"</span></code></pre></div>
|
||||
<h4 id="prev-getting-started"><a href="2_usage.html">Prev Getting started</a></h4>
|
||||
<h4 id="next-expert-use"><a href="4_expert.html">Next Expert Use</a></h4>
|
||||
<h4 id="version-v0.70-pre1-8-gfcca139"><br /><span class="math display"><em>V</em><em>E</em><em>R</em><em>S</em><em>I</em><em>O</em><em>N</em></span><br /> v0.70-pre1-8-gfcca139</h4>
|
||||
</body>
|
||||
</html>
|
124
html/4_expert.html
Normal file
124
html/4_expert.html
Normal file
@ -0,0 +1,124 @@
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<meta http-equiv="Content-Style-Type" content="text/css" />
|
||||
<meta name="generator" content="pandoc" />
|
||||
<title>Bashobot Documentation - 4_expert.html</title>
|
||||
<style type="text/css">code{white-space: pre;}</style>
|
||||
<style type="text/css">
|
||||
div.sourceCode { overflow-x: auto; }
|
||||
table.sourceCode, tr.sourceCode, td.lineNumbers, td.sourceCode {
|
||||
margin: 0; padding: 0; vertical-align: baseline; border: none; }
|
||||
table.sourceCode { width: 100%; line-height: 100%; }
|
||||
td.lineNumbers { text-align: right; padding-right: 4px; padding-left: 4px; color: #aaaaaa; border-right: 1px solid #aaaaaa; }
|
||||
td.sourceCode { padding-left: 5px; }
|
||||
code > span.kw { color: #007020; font-weight: bold; } /* Keyword */
|
||||
code > span.dt { color: #902000; } /* DataType */
|
||||
code > span.dv { color: #40a070; } /* DecVal */
|
||||
code > span.bn { color: #40a070; } /* BaseN */
|
||||
code > span.fl { color: #40a070; } /* Float */
|
||||
code > span.ch { color: #4070a0; } /* Char */
|
||||
code > span.st { color: #4070a0; } /* String */
|
||||
code > span.co { color: #60a0b0; font-style: italic; } /* Comment */
|
||||
code > span.ot { color: #007020; } /* Other */
|
||||
code > span.al { color: #ff0000; font-weight: bold; } /* Alert */
|
||||
code > span.fu { color: #06287e; } /* Function */
|
||||
code > span.er { color: #ff0000; font-weight: bold; } /* Error */
|
||||
code > span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warning */
|
||||
code > span.cn { color: #880000; } /* Constant */
|
||||
code > span.sc { color: #4070a0; } /* SpecialChar */
|
||||
code > span.vs { color: #4070a0; } /* VerbatimString */
|
||||
code > span.ss { color: #bb6688; } /* SpecialString */
|
||||
code > span.im { } /* Import */
|
||||
code > span.va { color: #19177c; } /* Variable */
|
||||
code > span.cf { color: #007020; font-weight: bold; } /* ControlFlow */
|
||||
code > span.op { color: #666666; } /* Operator */
|
||||
code > span.bu { } /* BuiltIn */
|
||||
code > span.ex { } /* Extension */
|
||||
code > span.pp { color: #bc7a00; } /* Preprocessor */
|
||||
code > span.at { color: #7d9029; } /* Attribute */
|
||||
code > span.do { color: #ba2121; font-style: italic; } /* Documentation */
|
||||
code > span.an { color: #60a0b0; font-weight: bold; font-style: italic; } /* Annotation */
|
||||
code > span.cv { color: #60a0b0; font-weight: bold; font-style: italic; } /* CommentVar */
|
||||
code > span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Information */
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="header">
|
||||
<h1 class="title">Bashobot Documentation - 4_expert.html</h1>
|
||||
</div>
|
||||
<h4 id="home"><a href="../README.html">Home</a></h4>
|
||||
<h2 id="expert-use">Expert Use</h2>
|
||||
<h3 id="handling-utf-8-character-sets">Handling UTF-8 character sets</h3>
|
||||
<p>UTF-8 is a variable length encoding of Unicode. UTF-8 is recommended as the default encoding in JSON, XML and HTML, also Telegram make use of it.</p>
|
||||
<p>The first 128 characters are regular ASCII, so it’s a superset of and compatible with ASCII environments. The next 1,920 characters need two bytes for encoding and covers almost all <code>Latin</code> alphabets, also <code>Greek</code>, <code>Cyrillic</code>, <code>Hebrew</code>, <code>Arabic</code> and more. See <a href="https://en.wikipedia.org/wiki/UTF-8">Wikipedia</a> for more details.</p>
|
||||
<h4 id="setting-up-your-environment">Setting up your Environment</h4>
|
||||
<p>In general <code>bash</code> and <code>GNU</code> utitities are UTF-8 aware if you to setup your environment and your scripts accordingly:</p>
|
||||
<ol style="list-style-type: decimal">
|
||||
<li><p>Your Terminal and Editor must support UTF-8: Set Terminal and Editor locale to UTF-8, eg. in <code>Settings/Configuration</code> select UTF-8 (Unicode) as Charset.</p></li>
|
||||
<li><p>Set <code>Shell</code> environment to UTF-8 in your <code>.profile</code> and your scripts. The usual settings are:</p></li>
|
||||
</ol>
|
||||
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="bu">export</span> <span class="st">'LC_ALL=C.UTF-8'</span>
|
||||
<span class="bu">export</span> <span class="st">'LANG=C.UTF-8'</span>
|
||||
<span class="bu">export</span> <span class="st">'LANGUAGE=C.UTF-8'</span></code></pre></div>
|
||||
<p>If you use other languages, eg. german or US english, change the shell settings to:</p>
|
||||
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="bu">export</span> <span class="st">'LC_ALL=de_DE.UTF-8'</span>
|
||||
<span class="bu">export</span> <span class="st">'LANG=de_DE.UTF-8'</span>
|
||||
<span class="bu">export</span> <span class="st">'LANGUAGE=de_DE.UTF-8'</span></code></pre></div>
|
||||
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="bu">export</span> <span class="st">'LC_ALL=en_US.UTF-8'</span>
|
||||
<span class="bu">export</span> <span class="st">'LANG=de_en_US.UTF-8'</span>
|
||||
<span class="bu">export</span> <span class="st">'LANGUAGE=den_US.UTF-8'</span></code></pre></div>
|
||||
<ol start="3" style="list-style-type: decimal">
|
||||
<li>make shure your bot scripts use the correct settings, eg. include the lines above at the beginning of your scripts</li>
|
||||
</ol>
|
||||
<p>To display all availible locales on your system run <code>locale -a | more</code>. <a href="https://wiki.gentoo.org/wiki/UTF-8">Gentoo Wiki</a></p>
|
||||
<h4 id="bashbot-utf-8-support">Bashbot UTF-8 Support</h4>
|
||||
<p>Bashbot handles all messages transparently, regardless of the charset in use. The only exception is when converting from JSON data to strings.</p>
|
||||
<p>Telegram use JSON to send / recieve data. JSON encodes strings as follow: Characters not ASCII <em>(>127)</em> are escaped as sequences of <code>\uxxxx</code> to be regular ASCII. In addition multibyte characters, <em>e.g. Emoticons or Arabic characters</em>, are send in double byte UTF-16 notation. The Emoticons <code>😁 😘 ❤️ 😊 👍</code> are encoded as: <code>\uD83D\uDE01 \uD83D\uDE18 \u2764\uFE0F \uD83D\uDE0A \uD83D\uDC4D</code></p>
|
||||
<p><strong>This “mixed” JSON encoding needs special handling and can not decoded from</strong> <code>echo -e</code> or <code>printf '%s\\n'</code></p>
|
||||
<p>Most complete support for decoding of multibyte characters can only be provided if python is installed on your system. <strong>Without phyton bashbot falls back to an internal, pure bash implementation which may not work for some corner cases</strong>.</p>
|
||||
<h3 id="run-as-other-user-or-system-service">Run as other user or system service</h3>
|
||||
<p>Bashbot is desingned to run manually by the user who installed it. Nevertheless it’s possible to run it by an other user-ID, as a system service or sceduled from cron. This is onyl recommended for experiend linux users.</p>
|
||||
<p>Setup the environment for the user you want to run bashbot and enter desired username, e.g. nobody :</p>
|
||||
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="fu">sudo</span> ./bashbot.sh init</code></pre></div>
|
||||
<p>Edit the file <code>bashbot.rc</code> and edit the following lines to fit your configuration:</p>
|
||||
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="co">#######################</span>
|
||||
<span class="co"># Configuration Section</span>
|
||||
|
||||
<span class="co"># edit the next line to fit the user you want to run bashbot, e.g. nobody:</span>
|
||||
<span class="va">runas=</span><span class="st">"nobody"</span>
|
||||
|
||||
<span class="co"># uncomment one of the following lines </span>
|
||||
<span class="co"># runcmd="su $runas -s /bin/bash -c " # runasuser with su</span>
|
||||
<span class="co"># runcmd="runuser $runas -s /bin/bash -c " # runasuser with runuser</span>
|
||||
|
||||
<span class="co"># edit the values of the following lines to fit your config:</span>
|
||||
<span class="va">start=</span><span class="st">"/usr/local/telegram-bot-bash/bashbot.sh"</span> <span class="co"># location of your bashbot.sh script</span>
|
||||
<span class="va">name=</span><span class="st">''</span> # <span class="ex">your</span> bot name as given to botfather, e.g. mysomething_bot
|
||||
|
||||
<span class="co"># </span><span class="re">END</span><span class="co"> Configuration</span>
|
||||
<span class="co">#######################</span></code></pre></div>
|
||||
<p>From now on use ‘bashbot.rc’ to manage your bot:</p>
|
||||
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="fu">sudo</span> ./bashbot.rc start</code></pre></div>
|
||||
<p>Type <code>ps -ef | grep bashbot</code> to verify your Bot is running as the desired user.</p>
|
||||
<p>If your Bot is started by ‘bashbot.rc’, you must use ‘bashbot.rc’ also to manage your Bot! The following commands are availible:</p>
|
||||
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="fu">sudo</span> ./bashbot.rc start
|
||||
<span class="fu">sudo</span> ./bashbot.rc stop
|
||||
<span class="fu">sudo</span> ./bashbot.rc status
|
||||
<span class="fu">sudo</span> ./bashbot.rc suspendback
|
||||
<span class="fu">sudo</span> ./bashbot.rc resumeback
|
||||
<span class="fu">sudo</span> ./bashbot.rc killback</code></pre></div>
|
||||
<p>To change back the environment to your user-ID run <code>sudo ./bashbot.sh init</code> again and enter your user name.</p>
|
||||
<p>To use bashbot as a system servive include a working <code>bashbot.rc</code> in your init system (systemd, /etc/init.d).</p>
|
||||
<h3 id="scedule-bashbot-from-cron">Scedule bashbot from Cron</h3>
|
||||
<p>An example crontab is provided in <code>examples/bashbot.cron</code>.</p>
|
||||
<ul>
|
||||
<li>If you are running bashbot with your user-ID, copy the examples lines to your crontab and remove username <code>nobody</code>.</li>
|
||||
<li>if you run bashbot as an other user or a system service edit <code>examples/bashbot.cron</code> to fit your needs and replace username<code>nobody</code> with the username you want to run bashbot. copy the modified file to <code>/etc/cron.d/bashbot</code></li>
|
||||
</ul>
|
||||
<h4 id="prev-expert-use"><a href="4_expert.html">Prev Expert Use</a></h4>
|
||||
<h4 id="next-best-practice"><a href="5_practice.html">Next Best Practice</a></h4>
|
||||
<h4 id="version-v0.70-pre1-0-g490c472"><br /><span class="math display"><em>V</em><em>E</em><em>R</em><em>S</em><em>I</em><em>O</em><em>N</em></span><br /> v0.70-pre1-0-g490c472</h4>
|
||||
</body>
|
||||
</html>
|
178
html/5_practice.html
Normal file
178
html/5_practice.html
Normal file
@ -0,0 +1,178 @@
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<meta http-equiv="Content-Style-Type" content="text/css" />
|
||||
<meta name="generator" content="pandoc" />
|
||||
<title>Bashobot Documentation - 5_practice.html</title>
|
||||
<style type="text/css">code{white-space: pre;}</style>
|
||||
<style type="text/css">
|
||||
div.sourceCode { overflow-x: auto; }
|
||||
table.sourceCode, tr.sourceCode, td.lineNumbers, td.sourceCode {
|
||||
margin: 0; padding: 0; vertical-align: baseline; border: none; }
|
||||
table.sourceCode { width: 100%; line-height: 100%; }
|
||||
td.lineNumbers { text-align: right; padding-right: 4px; padding-left: 4px; color: #aaaaaa; border-right: 1px solid #aaaaaa; }
|
||||
td.sourceCode { padding-left: 5px; }
|
||||
code > span.kw { color: #007020; font-weight: bold; } /* Keyword */
|
||||
code > span.dt { color: #902000; } /* DataType */
|
||||
code > span.dv { color: #40a070; } /* DecVal */
|
||||
code > span.bn { color: #40a070; } /* BaseN */
|
||||
code > span.fl { color: #40a070; } /* Float */
|
||||
code > span.ch { color: #4070a0; } /* Char */
|
||||
code > span.st { color: #4070a0; } /* String */
|
||||
code > span.co { color: #60a0b0; font-style: italic; } /* Comment */
|
||||
code > span.ot { color: #007020; } /* Other */
|
||||
code > span.al { color: #ff0000; font-weight: bold; } /* Alert */
|
||||
code > span.fu { color: #06287e; } /* Function */
|
||||
code > span.er { color: #ff0000; font-weight: bold; } /* Error */
|
||||
code > span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warning */
|
||||
code > span.cn { color: #880000; } /* Constant */
|
||||
code > span.sc { color: #4070a0; } /* SpecialChar */
|
||||
code > span.vs { color: #4070a0; } /* VerbatimString */
|
||||
code > span.ss { color: #bb6688; } /* SpecialString */
|
||||
code > span.im { } /* Import */
|
||||
code > span.va { color: #19177c; } /* Variable */
|
||||
code > span.cf { color: #007020; font-weight: bold; } /* ControlFlow */
|
||||
code > span.op { color: #666666; } /* Operator */
|
||||
code > span.bu { } /* BuiltIn */
|
||||
code > span.ex { } /* Extension */
|
||||
code > span.pp { color: #bc7a00; } /* Preprocessor */
|
||||
code > span.at { color: #7d9029; } /* Attribute */
|
||||
code > span.do { color: #ba2121; font-style: italic; } /* Documentation */
|
||||
code > span.an { color: #60a0b0; font-weight: bold; font-style: italic; } /* Annotation */
|
||||
code > span.cv { color: #60a0b0; font-weight: bold; font-style: italic; } /* CommentVar */
|
||||
code > span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Information */
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="header">
|
||||
<h1 class="title">Bashobot Documentation - 5_practice.html</h1>
|
||||
</div>
|
||||
<h4 id="home"><a href="../README.html">Home</a></h4>
|
||||
<h2 id="best-practices">Best Practices</h2>
|
||||
<h3 id="new-to-bot-development">New to bot development?</h3>
|
||||
<p>If you are new to Bot development read <a href="https://core.telegram.org/bots">Bots: An introduction for developers</a> and consult <a href="https://core.telegram.org/bots/api/">Telegram Bot API Documentation</a>.</p>
|
||||
<p>In addition you should know about <a href="https://core.telegram.org/bots#3-how-do-i-create-a-bot">BotFather, the one bot to rule them all</a>. It will help you create new bots and change settings for existing ones. <a href="https://core.telegram.org/bots#generating-an-authorization-token">Commands known by Botfather</a></p>
|
||||
<p>If you dont’t have a github account, it may time to <a href="https://github.com/pricing">sepup a free account now</a></p>
|
||||
<h3 id="add-commands-to-mycommands.sh-only">Add commands to mycommands.sh only</h3>
|
||||
<p>To ease updates never change <code>bashbot.sh</code>, instead your commands and functions must go to <code>mycommands.sh</code> . Insert your Bot commands in the <code>case ... esac</code> block of the ‘mycommands()’ function:</p>
|
||||
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="co"># file: mycommands.sh</span>
|
||||
<span class="co"># your additional bahsbot commands</span>
|
||||
|
||||
<span class="co"># uncomment the following lines to overwrite info and help messages</span>
|
||||
<span class="va">bashbot_info=</span><span class="st">'This is *MY* variant of _bashbot_, the Telegram bot written entirely in bash.</span>
|
||||
<span class="st">'</span>
|
||||
|
||||
<span class="va">bashbot_help=</span><span class="st">'*Available commands*:</span>
|
||||
<span class="st">/echo message - _echo the given messsage_</span>
|
||||
<span class="st">'</span>
|
||||
|
||||
<span class="co"># </span><span class="al">NOTE</span><span class="co">: command can have @botname attached, you must add * in case tests... </span>
|
||||
<span class="fu">mycommands()</span> <span class="kw">{</span>
|
||||
|
||||
<span class="kw">case</span> <span class="st">"</span><span class="va">$MESSAGE</span><span class="st">"</span><span class="kw"> in</span>
|
||||
<span class="st">'/echo'</span>*<span class="kw">)</span> <span class="co"># example echo command</span>
|
||||
<span class="ex">send_normal_message</span> <span class="st">"</span><span class="va">${CHAT[ID]}</span><span class="st">"</span> <span class="st">"</span><span class="va">$MESSAGE</span><span class="st">"</span>
|
||||
<span class="kw">;;</span>
|
||||
<span class="co"># .....</span>
|
||||
<span class="kw">esac</span>
|
||||
<span class="kw">}</span></code></pre></div>
|
||||
<h3 id="reuse-or-disable-global-commands">Reuse or disable global commands</h3>
|
||||
<p>If you want to disable or reuse a global bashbot command comment it out in ‘commands.sh’ by placing a ‘#’ in front of every line from <code>'/command')</code> to <code>;;</code>.</p>
|
||||
<p><strong>Learn more about <a href="https://core.telegram.org/bots#commands">Bot commands</a>.</strong></p>
|
||||
<p><strong>Note: Never disable the catchall command <code>*)</code> in ‘commands.sh’!!</strong></p>
|
||||
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="co"># file: commands.sh</span>
|
||||
|
||||
<span class="kw">case</span> <span class="st">"</span><span class="va">$MESSAGE</span><span class="st">"</span><span class="kw"> in</span>
|
||||
<span class="co">################################################</span>
|
||||
<span class="co"># GLOBAL commands start here, edit messages only</span>
|
||||
|
||||
<span class="co">#'/start'*)</span>
|
||||
<span class="co"># send_action "${CHAT[ID]}" "typing"</span>
|
||||
<span class="co"># _is_botadmin && _markdown_message "You are *BOTADMIN*."</span>
|
||||
<span class="co"># if _is_allowed "start" ; then</span>
|
||||
<span class="co"># _markdown_message "${bot_help}"</span>
|
||||
<span class="co"># else</span>
|
||||
<span class="co"># _message "You are not allowed to start Bot."</span>
|
||||
<span class="co"># fi</span>
|
||||
<span class="co"># ;;</span>
|
||||
|
||||
*<span class="kw">)</span> # <span class="ex">forward</span> other messages to optional dispatcher
|
||||
<span class="ex">_is_function</span> startproc <span class="kw">&&</span> <span class="kw">if</span> <span class="ex">tmux</span> ls <span class="kw">|</span> <span class="fu">grep</span> -v send <span class="kw">|</span> <span class="fu">grep</span> -q <span class="st">"</span><span class="va">$copname</span><span class="st">"</span><span class="kw">;</span> <span class="kw">then</span> <span class="ex">inproc</span><span class="kw">;</span> <span class="kw">fi</span> <span class="co"># interactive running</span>
|
||||
<span class="ex">_is_function</span> mycommands <span class="kw">&&</span> <span class="ex">mycommands</span>
|
||||
<span class="kw">;;</span>
|
||||
<span class="kw">esac</span></code></pre></div>
|
||||
<h3 id="seperate-logic-from-commands">Seperate logic from commands</h3>
|
||||
<p>If a command need more than 2-3 lines of code, you should use a function to seperate logic from command. Place your functions in <code>mycommands.sh</code> and call the from your command. Example:</p>
|
||||
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="co"># file: mycommands.sh</span>
|
||||
<span class="co"># your additional bahsbot commands</span>
|
||||
|
||||
<span class="fu">mycommands()</span> <span class="kw">{</span>
|
||||
|
||||
<span class="kw">case</span> <span class="st">"</span><span class="va">$MESSAGE</span><span class="st">"</span><span class="kw"> in</span>
|
||||
<span class="st">'/process'</span>*<span class="kw">)</span> <span class="co"># logic for /process is done in process_message </span>
|
||||
<span class="va">result=</span><span class="st">"</span><span class="va">$(</span><span class="ex">process_message</span> <span class="st">"</span><span class="va">$MESSAGE</span><span class="st">"</span><span class="va">)</span><span class="st">"</span>
|
||||
<span class="ex">send_normal_message</span> <span class="st">"</span><span class="va">${CHAT[ID]}</span><span class="st">"</span> <span class="st">"</span><span class="va">$result</span><span class="st">"</span>
|
||||
<span class="kw">;;</span>
|
||||
<span class="kw">esac</span>
|
||||
|
||||
<span class="kw">}</span>
|
||||
|
||||
<span class="co"># place your functions here</span>
|
||||
|
||||
<span class="fu">process_message()</span> <span class="kw">{</span>
|
||||
<span class="bu">local</span> <span class="va">ARGS=</span><span class="st">"</span><span class="va">${1#</span>/* <span class="va">}</span><span class="st">"</span> <span class="co"># remove command </span>
|
||||
<span class="bu">local</span> <span class="va">TEXT</span> <span class="va">OUTPUT=</span><span class="st">""</span>
|
||||
|
||||
<span class="co"># process every word in MESSAGE, avoid globbing</span>
|
||||
<span class="kw">set</span> <span class="ex">-f</span>
|
||||
<span class="kw">for</span> <span class="ex">WORD</span> in <span class="va">$ARGS</span>
|
||||
<span class="kw">do</span>
|
||||
<span class="co"># process links </span>
|
||||
<span class="kw">if [[</span> <span class="st">"</span><span class="va">$WORD</span><span class="st">"</span> <span class="ot">==</span> <span class="st">"https://"</span>*<span class="kw"> ]]</span>; <span class="kw">then</span>
|
||||
<span class="va">REPORT=</span><span class="st">"</span><span class="va">$(</span><span class="ex">dosomething_with_link</span> <span class="st">"</span><span class="va">$WORD</span><span class="st">"</span><span class="va">)</span><span class="st">"</span>
|
||||
<span class="co"># no link, add as text</span>
|
||||
<span class="kw">else</span>
|
||||
<span class="va">TEXT=</span><span class="st">"</span><span class="va">$(</span><span class="bu">echo</span> <span class="st">"</span><span class="va">${TEXT}</span><span class="st"> </span><span class="va">$WORD</span><span class="st">"</span><span class="va">)</span><span class="st">"</span>
|
||||
<span class="bu">continue</span>
|
||||
<span class="kw">fi</span>
|
||||
<span class="co"># compose result</span>
|
||||
<span class="va">OUTPUT=</span><span class="st">"* </span><span class="va">${REPORT}</span><span class="st"> </span><span class="va">${WORD}</span><span class="st"> </span><span class="va">${TEXT}</span><span class="st">"</span>
|
||||
<span class="va">TEXT=</span><span class="st">""</span>
|
||||
<span class="kw">done</span>
|
||||
|
||||
<span class="co"># return result, reset globbing in case we had no ARGS</span>
|
||||
<span class="bu">echo</span> <span class="st">"</span><span class="va">${OUTPUT}${TEXT}</span><span class="st">"</span>
|
||||
<span class="kw">}</span></code></pre></div>
|
||||
<h3 id="test-your-bot-with-shellcheck">Test your Bot with shellcheck</h3>
|
||||
<p>Shellcheck is a static linter for shell scripts providing excellent tips and hints for shell coding pittfalls. You can <a href="https://www.shellcheck.net/">use it online</a> or <a href="https://github.com/koalaman/shellcheck#installing">install it on your system</a>. All bashbot scripts are linted by shellcheck.</p>
|
||||
<p>Shellcheck examples:</p>
|
||||
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash">$ <span class="ex">shellcheck</span> -x mybotcommands.inc.sh
|
||||
|
||||
<span class="ex">Line</span> 17:
|
||||
<span class="va">TEXT=</span><span class="st">"</span><span class="va">$(</span><span class="bu">echo</span> <span class="st">"</span><span class="va">${TEXT}</span><span class="st"> </span><span class="va">$WORD</span><span class="st">"</span><span class="va">)</span><span class="st">"</span>
|
||||
^<span class="ex">--</span> SC2116: Useless echo? Instead of <span class="st">'cmd $(echo foo)'</span>, just use <span class="st">'cmd foo'</span>.
|
||||
</code></pre></div>
|
||||
<p>As you can see my <code>mybotcommands.inc.sh</code> contains an useless echo command in ‘TEXT=’ assigment and can be replaced by <code>TEXT="${TEXT}${WORD}"</code></p>
|
||||
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash">$ <span class="ex">shellcheck</span> -x examples/notify
|
||||
<span class="ex">OK</span>
|
||||
$ <span class="ex">shellcheck</span> -x examples/question
|
||||
<span class="ex">OK</span>
|
||||
$ <span class="ex">shellcheck</span> -x commands.sh
|
||||
<span class="ex">OK</span>
|
||||
$ <span class="ex">shellcheck</span> -x bashbot.sh
|
||||
|
||||
<span class="ex">In</span> bashbot.sh line 123:
|
||||
<span class="va">text=</span><span class="st">"</span><span class="va">$(</span><span class="bu">echo</span> <span class="st">"</span><span class="va">$text</span><span class="st">"</span> <span class="kw">|</span> <span class="fu">sed</span> <span class="st">'s/ mynewlinestartshere /\r\n/g'</span><span class="va">)</span><span class="st">"</span> <span class="co"># hack for linebreaks in startproc scripts</span>
|
||||
^<span class="ex">--</span> SC2001: See if you can use <span class="va">${variable//</span>search<span class="va">/</span>replace<span class="va">}</span> instead.
|
||||
|
||||
|
||||
<span class="ex">In</span> bashbot.sh line 490:
|
||||
<span class="va">CONTACT[USER_ID]=</span><span class="st">"</span><span class="va">$(</span><span class="fu">sed</span> -n -e <span class="st">'/\["result",'</span><span class="va">$PROCESS_NUMBER</span><span class="st">',"message","contact","user_id"\]/ s/.*\][ \t]"\(.*\)"$/\1/p'</span> <span class="op"><</span><span class="st">"</span><span class="va">$TMP</span><span class="st">"</span><span class="va">)</span><span class="st">"</span>
|
||||
^<span class="ex">--</span> SC2034: CONTACT appears unused. Verify it or export it.</code></pre></div>
|
||||
<p>The example show two warnings in bashbots scripts. The first is a hint you may use shell substitions instead of sed, this is fixed and much faster as the “echo | sed” solution. The second warning is about an unused variable, this is true because in our examples CONTACT is not used but assigned in case you want to use it :-)</p>
|
||||
<h4 id="prev-best-practice"><a href="5_practice.html">Prev Best Practice</a></h4>
|
||||
<h4 id="next-functions-reference"><a href="6_reference.html">Next Functions Reference</a></h4>
|
||||
<h4 id="version-v0.70-pre1-7-g02d9afb"><br /><span class="math display"><em>V</em><em>E</em><em>R</em><em>S</em><em>I</em><em>O</em><em>N</em></span><br /> v0.70-pre1-7-g02d9afb</h4>
|
||||
</body>
|
||||
</html>
|
334
html/6_reference.html
Normal file
334
html/6_reference.html
Normal file
@ -0,0 +1,334 @@
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<meta http-equiv="Content-Style-Type" content="text/css" />
|
||||
<meta name="generator" content="pandoc" />
|
||||
<title>Bashobot Documentation - 6_reference.html</title>
|
||||
<style type="text/css">code{white-space: pre;}</style>
|
||||
<style type="text/css">
|
||||
div.sourceCode { overflow-x: auto; }
|
||||
table.sourceCode, tr.sourceCode, td.lineNumbers, td.sourceCode {
|
||||
margin: 0; padding: 0; vertical-align: baseline; border: none; }
|
||||
table.sourceCode { width: 100%; line-height: 100%; }
|
||||
td.lineNumbers { text-align: right; padding-right: 4px; padding-left: 4px; color: #aaaaaa; border-right: 1px solid #aaaaaa; }
|
||||
td.sourceCode { padding-left: 5px; }
|
||||
code > span.kw { color: #007020; font-weight: bold; } /* Keyword */
|
||||
code > span.dt { color: #902000; } /* DataType */
|
||||
code > span.dv { color: #40a070; } /* DecVal */
|
||||
code > span.bn { color: #40a070; } /* BaseN */
|
||||
code > span.fl { color: #40a070; } /* Float */
|
||||
code > span.ch { color: #4070a0; } /* Char */
|
||||
code > span.st { color: #4070a0; } /* String */
|
||||
code > span.co { color: #60a0b0; font-style: italic; } /* Comment */
|
||||
code > span.ot { color: #007020; } /* Other */
|
||||
code > span.al { color: #ff0000; font-weight: bold; } /* Alert */
|
||||
code > span.fu { color: #06287e; } /* Function */
|
||||
code > span.er { color: #ff0000; font-weight: bold; } /* Error */
|
||||
code > span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warning */
|
||||
code > span.cn { color: #880000; } /* Constant */
|
||||
code > span.sc { color: #4070a0; } /* SpecialChar */
|
||||
code > span.vs { color: #4070a0; } /* VerbatimString */
|
||||
code > span.ss { color: #bb6688; } /* SpecialString */
|
||||
code > span.im { } /* Import */
|
||||
code > span.va { color: #19177c; } /* Variable */
|
||||
code > span.cf { color: #007020; font-weight: bold; } /* ControlFlow */
|
||||
code > span.op { color: #666666; } /* Operator */
|
||||
code > span.bu { } /* BuiltIn */
|
||||
code > span.ex { } /* Extension */
|
||||
code > span.pp { color: #bc7a00; } /* Preprocessor */
|
||||
code > span.at { color: #7d9029; } /* Attribute */
|
||||
code > span.do { color: #ba2121; font-style: italic; } /* Documentation */
|
||||
code > span.an { color: #60a0b0; font-weight: bold; font-style: italic; } /* Annotation */
|
||||
code > span.cv { color: #60a0b0; font-weight: bold; font-style: italic; } /* CommentVar */
|
||||
code > span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Information */
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="header">
|
||||
<h1 class="title">Bashobot Documentation - 6_reference.html</h1>
|
||||
</div>
|
||||
<h4 id="home"><a href="../README.html">Home</a></h4>
|
||||
<h2 id="bashbot-function-reference">Bashbot function reference</h2>
|
||||
<h3 id="send-forward-delete-messages">Send, forward, delete messages</h3>
|
||||
<h5 id="send_action">send_action</h5>
|
||||
<p><code>send_action</code> shows users what your bot is currently doing.</p>
|
||||
<p><em>usage:</em> send_action “${CHAT[ID]}” “action”</p>
|
||||
<p><em>“action”:</em> <code>typing</code>, <code>upload_photo</code>, <code>record_video</code>, <code>upload_video</code>, <code>record_audio</code>, <code>upload_audio</code>, <code>upload_document</code>, <code>find_location</code>.</p>
|
||||
<p><em>example:</em></p>
|
||||
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="ex">send_action</span> <span class="st">"</span><span class="va">${CHAT[ID]}</span><span class="st">"</span> <span class="st">"typing"</span>
|
||||
<span class="ex">send_action</span> <span class="st">"</span><span class="va">${CHAT[ID]}</span><span class="st">"</span> <span class="st">"record_audio"</span></code></pre></div>
|
||||
<h5 id="send_normal_message">send_normal_message</h5>
|
||||
<p><code>send_normal_message</code> sends text only messages to the given chat.</p>
|
||||
<p><em>usage:</em> send_normal_message “${CHAT[ID]}” “message”</p>
|
||||
<p><em>example:</em></p>
|
||||
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="ex">send_normal_message</span> <span class="st">"</span><span class="va">${CHAT[ID]}</span><span class="st">"</span> <span class="st">"this is a text message"</span></code></pre></div>
|
||||
<h5 id="send_markdown_message">send_markdown_message</h5>
|
||||
<p><code>send_markdown_message</code> sends markdown style messages to the given chat. Telegram supports a <a href="https://core.telegram.org/bots/api#markdown-style">reduced set of Markdown</a> only</p>
|
||||
<p><em>usage:</em> send_markdown_message “${CHAT[ID]}” “markdown message”</p>
|
||||
<p><em>example:</em></p>
|
||||
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="ex">send_markdown_message</span> <span class="st">"</span><span class="va">${CHAT[ID]}</span><span class="st">"</span> <span class="st">"this is a markdown message, next word is *bold*"</span>
|
||||
<span class="ex">send_markdown_message</span> <span class="st">"</span><span class="va">${CHAT[ID]}</span><span class="st">"</span> <span class="st">"*bold* _italic_ [text](link)"</span></code></pre></div>
|
||||
<h5 id="send_html_message">send_html_message</h5>
|
||||
<p><code>send_html_message</code> sends HTML style messages to the given chat. Telegram supports a <a href="https://core.telegram.org/bots/api#html-style">reduced set of HTML</a> only</p>
|
||||
<p><em>usage:</em> send_html_message “${CHAT[ID]}” “html message”</p>
|
||||
<p><em>example:</em></p>
|
||||
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="ex">send_normal_message</span> <span class="st">"</span><span class="va">${CHAT[ID]}</span><span class="st">"</span> <span class="st">"this is a markdown message, next word is <b>bold</b>"</span>
|
||||
<span class="ex">send_normal_message</span> <span class="st">"</span><span class="va">${CHAT[ID]}</span><span class="st">"</span> <span class="st">"<b>bold</b> <i>italic><i> <em>italic>/em> <a href="</span>link<span class="st">">Text</a>"</span></code></pre></div>
|
||||
<h5 id="forward_message">forward_message</h5>
|
||||
<p><code>forward_mesage</code> forwards a messsage to the given chat.</p>
|
||||
<p><em>usage:</em> forward_message “chat_to” “chat_from” “${MESSAGE[ID]}”</p>
|
||||
<p><em>old call:</em> forward “<span class="math inline">${CHAT[ID]}" "$</span>FROMCHAT” “${MESSAGE[ID]}”</p>
|
||||
<p>See also <a href="https://core.telegram.org/bots/api#formatting-options">Text formating options</a></p>
|
||||
<hr />
|
||||
<h5 id="delete_message">delete_message</h5>
|
||||
<p>If your Bot is admin of a Chat he can delete every message, if not he can delete only his messages.</p>
|
||||
<p><em>usage:</em> delete_message “<span class="math inline">${CHAT[ID]}" "$</span>{MESSAGE[ID]}”</p>
|
||||
<p>See also <a href="https://core.telegram.org/bots/api#deletemessage">deleteMessage limitations</a></p>
|
||||
<hr />
|
||||
<h5 id="answer_inline_query">answer_inline_query</h5>
|
||||
<p>Inline Queries allows users to interact with your bot directly without sending extra commands. answer_inline_query provide the result to a users Inline Query</p>
|
||||
<p><em>usage:</em> answer_inline_query “$iQUERY_ID” “type” “type arg 1” … “type arg n”</p>
|
||||
<p><em>example:</em> - see <a href="3_advanced.md#Inline-queries">Advanced Usage</a></p>
|
||||
<hr />
|
||||
<h3 id="file-location-venue-keyboard">File, Location, Venue, Keyboard</h3>
|
||||
<h5 id="send_file">send_file</h5>
|
||||
<p>send_file allows you to send different type’s of files, e.g. photos, stickers, audio, media, etc. <a href="https://core.telegram.org/bots/api#sending-files">see more</a></p>
|
||||
<p><em>usage:</em> send_file “${CHAT[ID]}” “file” “caption”</p>
|
||||
<p><em>example:</em></p>
|
||||
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="ex">send_file</span> <span class="st">"</span><span class="va">${CHAT[ID]}</span><span class="st">"</span> <span class="st">"/home/user/doge.jpg"</span> <span class="st">"Lool"</span>
|
||||
<span class="ex">send_file</span> <span class="st">"</span><span class="va">${CHAT[ID]}</span><span class="st">"</span> <span class="st">"https://www.domain,com/something.gif"</span> <span class="st">"Something"</span></code></pre></div>
|
||||
<h5 id="send_location">send_location</h5>
|
||||
<p><em>usage:</em> send_location “${CHAT[ID]}” “Latitude” “Longitude”</p>
|
||||
<h5 id="send_venue">send_venue</h5>
|
||||
<p><em>usage:</em> send_venue “${CHAT[ID]}” “Latitude” “Longitude” “Title” “Address” “foursquare id (optional)”</p>
|
||||
<hr />
|
||||
<h5 id="send_keyboard">send_keyboard</h5>
|
||||
<p>Note: since version 0.6 send_keyboard was changed to use native “JSON Array” notation as used from Telegram. Example Keybord Array definitions:</p>
|
||||
<ul>
|
||||
<li>yes no in two rows:
|
||||
<ul>
|
||||
<li>OLD format: ‘yes’ ‘no’ (two strings)</li>
|
||||
<li>NEW format: ‘[ “yes” ] , [ “no” ]’ (two arrays with a string)</li>
|
||||
</ul></li>
|
||||
<li>new layouts made easy with NEW format:
|
||||
<ul>
|
||||
<li>Yes No in one row: ‘[ “yes” , “no” ]’</li>
|
||||
<li>Yes No plus Maybe in 2.row: ‘[ “yes” , “no” ] , [ “maybe” ]’</li>
|
||||
<li>numpad style keyboard: ‘[ “1” , “2” , “3” ] , [ “4” , “5” , “6” ] , [ “7” , “8” , “9” ] , [ “0” ]’</li>
|
||||
</ul></li>
|
||||
</ul>
|
||||
<p><em>usage:</em> send_keyboard “chat-id” “message” “keyboard”</p>
|
||||
<p><em>example:</em></p>
|
||||
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="ex">send_keyboard</span> <span class="st">"</span><span class="va">${CHAT[ID]}</span><span class="st">"</span> <span class="st">"Say yes or no"</span> <span class="st">"[ </span><span class="dt">\\</span><span class="st">"</span>yes<span class="dt">\"</span> , <span class="dt">\\</span><span class="st">"no</span><span class="dt">\"</span><span class="st"> ]""</span>
|
||||
<span class="st">send_keyboard "</span><span class="va">${CHAT[ID]}</span><span class="st">" "</span>Say yes or no<span class="st">" "</span>[ <span class="dt">\\</span><span class="st">"yes</span><span class="dt">\\</span><span class="st">"</span> ] , [ <span class="dt">\\</span><span class="st">"no</span><span class="dt">\\</span><span class="st">"</span> ]<span class="st">"</span>
|
||||
<span class="st">send_keyboard "</span><span class="va">${CHAT[ID]}</span><span class="st">" "</span>Enter digit<span class="st">" "</span>[ <span class="dt">\\</span><span class="st">"1</span><span class="dt">\\</span><span class="st">"</span> , <span class="dt">\\</span><span class="st">"2</span><span class="dt">\\</span><span class="st">"</span> , <span class="dt">\\</span><span class="st">"3</span><span class="dt">\\</span><span class="st">"</span> ] , [ <span class="dt">\\</span><span class="st">"4</span><span class="dt">\\</span><span class="st">"</span> , <span class="dt">\\</span><span class="st">"5</span><span class="dt">\\</span><span class="st">"</span> , <span class="dt">\\</span><span class="st">"6</span><span class="dt">\\</span><span class="st">"</span> ] , [ <span class="dt">\\</span><span class="st">"7</span><span class="dt">\\</span><span class="st">"</span> , <span class="dt">\\</span><span class="st">"8</span><span class="dt">\\</span><span class="st">"</span> , <span class="dt">\\</span><span class="st">"9</span><span class="dt">\\</span><span class="st">"</span> ] , [ <span class="dt">\\</span><span class="st">"0</span><span class="dt">\\</span><span class="st">"</span> ]<span class="st">"</span></code></pre></div>
|
||||
<h5 id="remove_keyboard">remove_keyboard</h5>
|
||||
<p><em>usage:</em> remove_keybord “$CHAT[ID]” “message”</p>
|
||||
<p><em>See also: <a href="https://core.telegram.org/bots/api/#replykeyboardmarkup">Keyboard Markup</a></em></p>
|
||||
<hr />
|
||||
<h5 id="send_button">send_button</h5>
|
||||
<p><em>usage:</em> send_button “chat-id” “message” “text” “URL”</p>
|
||||
<p><em>alias:</em> _button “text” “URL”</p>
|
||||
<p><em>example:</em></p>
|
||||
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="ex">send_button</span> <span class="st">"</span><span class="va">${CHAT[ID]}</span><span class="st">"</span> <span class="st">"MAKE MONEY FAST!!!"</span> <span class="st">"Visit my Shop"</span> <span class="st">"https://dealz.rrr.de"</span></code></pre></div>
|
||||
<h5 id="send_inline_keyboard">send_inline_keyboard</h5>
|
||||
<p>This allows to place multiple inline buttons in a row. The inline buttons must specified as a JSON array in the following format:</p>
|
||||
<p><code>[ {"text":"text1", "url":"url1"}, ... {"text":"textN", "url":"urlN"} ]</code></p>
|
||||
<p>Each button consists of a pair of text and URL values, sourrounded by ‘{ }’, multiple buttons are seperated by ‘<strong>,</strong>’ and everthing is wrapped in ‘[ ]’.</p>
|
||||
<p><em>usage:</em> send_inline_keyboard “chat-id” “message” “[ {“text”:“text”, “url”:“url”} …]”</p>
|
||||
<p><em>alias:</em> _inline_keyboard “[{“text”:“text”, “url”:“url”} …]”</p>
|
||||
<p><em>example:</em></p>
|
||||
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="ex">send_inline_keyboard</span> <span class="st">"</span><span class="va">${CHAT[ID]}</span><span class="st">"</span> <span class="st">"MAKE MONEY FAST!!!"</span> <span class="st">'[{"text":"Visit my Shop", url"":"https://dealz.rrr.de"}]'</span>
|
||||
<span class="ex">send_inline_keyboard</span> <span class="st">"</span><span class="va">${CHAT[ID]}</span><span class="st">"</span> <span class="st">""</span> <span class="st">'[{"text":"button 1", url"":"url 1"}, {"text":"button 2", url"":"url 2"} ]'</span>
|
||||
<span class="ex">send_inline_keyboard</span> <span class="st">"</span><span class="va">${CHAT[ID]}</span><span class="st">"</span> <span class="st">""</span> <span class="st">'[{"text":"b 1", url"":"u 1"}, {"text":"b 2", url"":"u 2"}, {"text":"b 2", url"":"u 2"} ]'</span></code></pre></div>
|
||||
<p><em>See also <a href="https://core.telegram.org/bots/api/#inlinekeyboardmarkup">Inline keyboard markup</a></em></p>
|
||||
<hr />
|
||||
<h3 id="manage-users">Manage users</h3>
|
||||
<h5 id="kick_chat_member">kick_chat_member</h5>
|
||||
<p>If your Bot is a chat admin he can kick and ban a user.</p>
|
||||
<p><em>usage:</em> kick_chat_member “<span class="math inline">${CHAT[ID]}" "$</span>{USER[ID]}”</p>
|
||||
<p><em>alias:</em> _kick_user “${USER[ID]}”</p>
|
||||
<h5 id="unban_chat_member">unban_chat_member</h5>
|
||||
<p>If your Bot is a chat admine can unban a kicked user.</p>
|
||||
<p><em>usage:</em> unban_chat_member “<span class="math inline">${CHAT[ID]}" "$</span>{USER[ID]}”</p>
|
||||
<p><em>alias:</em> _unban “${USER[ID]}”</p>
|
||||
<h5 id="leave_chat">leave_chat</h5>
|
||||
<p>Your Bot will leave the chat.</p>
|
||||
<p><em>usage:</em> leave_chat “${CHAT[ID]}”</p>
|
||||
<p><em>alias:</em> _leave</p>
|
||||
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="kw">if</span> <span class="ex">_is_admin</span> <span class="kw">;</span> <span class="kw">then</span>
|
||||
<span class="ex">send_markdown_message</span> <span class="st">"</span><span class="va">${CHAT[ID]}</span><span class="st">"</span> <span class="st">"*LEAVING CHAT...*"</span>
|
||||
<span class="ex">leave_chat</span> <span class="st">"</span><span class="va">${CHAT[ID]}</span><span class="st">"</span>
|
||||
<span class="kw">fi</span></code></pre></div>
|
||||
<p>’See also <a href="https://core.telegram.org/bots/api/#kickchatmember">kick Chat Member</a>*</p>
|
||||
<hr />
|
||||
<h3 id="user-access-control">User Access Control</h3>
|
||||
<h5 id="user_is_botadmin">user_is_botadmin</h5>
|
||||
<p>Return true (0) if user is admin of bot, user id if botadmin is read from file ‘./botadmin’.</p>
|
||||
<p><em>usage:</em> user_is_botadmin “${USER[ID]}”</p>
|
||||
<p><em>modules/alias:</em> _is_botadmin</p>
|
||||
<p><em>example:</em></p>
|
||||
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"> <span class="ex">_is_botadmin</span> <span class="kw">&&</span> <span class="ex">send_markdown_message</span> <span class="st">"</span><span class="va">${CHAT[ID]}</span><span class="st">"</span> <span class="st">"You are *BOTADMIN*."</span></code></pre></div>
|
||||
<h5 id="user_is_creator">user_is_creator</h5>
|
||||
<p>Return true (0) if user is creator of given chat or chat is a private chat.</p>
|
||||
<p><em>usage:</em> user_is_creator “<span class="math inline">${CHAT[ID]}" "$</span>{USER[ID]}”</p>
|
||||
<p><em>modules/alias:</em> _is_creator</p>
|
||||
<h5 id="user_is_admin">user_is_admin</h5>
|
||||
<p>Return true (0) if user is admin or creator of given chat.</p>
|
||||
<p><em>usage:</em> user_is_admin “<span class="math inline">${CHAT[ID]}" "$</span>{USER[ID]}”</p>
|
||||
<p><em>modules/alias:</em> _is_admin</p>
|
||||
<p><em>example:</em></p>
|
||||
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="kw">if</span> <span class="ex">_is_admin</span> <span class="kw">;</span> <span class="kw">then</span>
|
||||
<span class="ex">send_markdown_message</span> <span class="st">"</span><span class="va">${CHAT[ID]}</span><span class="st">"</span> <span class="st">"*LEAVING CHAT...*"</span>
|
||||
<span class="ex">leave_chat</span> <span class="st">"</span><span class="va">${CHAT[ID]}</span><span class="st">"</span>
|
||||
<span class="kw">fi</span></code></pre></div>
|
||||
<p><em>See also <a href="https://core.telegram.org/bots/api/#chatmember">Chat Member</a></em></p>
|
||||
<h5 id="user_is_allowed">user_is_allowed</h5>
|
||||
<p>Bahsbot supports User Access Control, see <a href="4_advanced.html">Advanced Usage</a></p>
|
||||
<p><em>usage:</em> user_is_allowed “<span class="math inline">${USER[ID]}" "what" "$</span>{CHAT[ID]}”</p>
|
||||
<p><em>example:</em></p>
|
||||
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="kw">if</span> ! <span class="ex">user_is_allowed</span> <span class="st">"</span><span class="va">${USER[ID]}</span><span class="st">"</span> <span class="st">"start"</span> <span class="st">"</span><span class="va">${CHAT[ID]}</span><span class="st">"</span> <span class="kw">;</span> <span class="kw">then</span>
|
||||
<span class="ex">send_normal_message</span> <span class="st">"</span><span class="va">${CHAT[ID]}</span><span class="st">"</span> <span class="st">"You are not allowed to start Bot."</span>
|
||||
<span class="kw">fi</span></code></pre></div>
|
||||
<hr />
|
||||
<h3 id="aliases---shortcuts-for-often-used-funtions">Aliases - shortcuts for often used funtions</h3>
|
||||
<p>You must not disable <code>source modules/aliases.sh</code> in ‘commands.sh’ to have the following functions availible.</p>
|
||||
<h5 id="is_botadmin">_is_botadmin</h5>
|
||||
<p><em>usage:</em> _is_botadmin</p>
|
||||
<p><em>alias for:</em> user_is_botadmin “${USER[ID]}”</p>
|
||||
<h5 id="is_admin">_is_admin</h5>
|
||||
<p><em>usage:</em> _is_admin</p>
|
||||
<p><em>alias for:</em> user_is_admin “<span class="math inline">${CHAT[ID]}" "$</span>{USER[ID]}”</p>
|
||||
<h5 id="is_allowed">_is_allowed</h5>
|
||||
<p><em>usage:</em> _is_allowed “what”</p>
|
||||
<p><em>alias for:</em> user_is_allowed “<span class="math inline">${USER[ID]}" "what" "$</span>{CHAT[ID]}”</p>
|
||||
<hr />
|
||||
<h5 id="kick_user">_kick_user</h5>
|
||||
<p><em>usage:</em> _kick_user “${USER[ID]}”</p>
|
||||
<p><em>alias for:</em> kick_chat_member “<span class="math inline">${CHAT[ID]}" "$</span>{USER[ID]}”</p>
|
||||
<h5 id="unban">_unban</h5>
|
||||
<p><em>usage:</em> _unban “${USER[ID]}”</p>
|
||||
<p><em>alias for:</em> unban_chat_member “<span class="math inline">${CHAT[ID]}" "$</span>{USER[ID]}”</p>
|
||||
<h5 id="leave">_leave</h5>
|
||||
<p><em>usage:</em> _leave</p>
|
||||
<p><em>alias for:</em> leave_chat “${CHAT[ID]}”</p>
|
||||
<hr />
|
||||
<h5 id="message">_message</h5>
|
||||
<p><em>usage:</em> _message “message”</p>
|
||||
<p><em>alias for:</em> send_normal_message “${CHAT[ID]}” “message”</p>
|
||||
<h5 id="normal_message">_normal_message</h5>
|
||||
<p><em>usage:</em> _normal_message “message”</p>
|
||||
<p><em>alias for:</em> send_normal_message “${CHAT[ID]}” “message”</p>
|
||||
<h5 id="html_message">_html_message</h5>
|
||||
<p><em>usage:</em> _html_message “message”</p>
|
||||
<p><em>alias for:</em> send_html_message “${CHAT[ID]}” “message”</p>
|
||||
<h5 id="markdown_message">_markdown_message</h5>
|
||||
<p><em>usage:</em> _markdown_message “message”</p>
|
||||
<p><em>alias for:</em> send_markdown_message “${CHAT[ID]}” “message”</p>
|
||||
<hr />
|
||||
<h3 id="interactive-and-backgound-jobs">Interactive and backgound jobs</h3>
|
||||
<p>You must not disable <code>source modules/background.sh</code> in ‘commands.sh’ to have the following functions availible.</p>
|
||||
<h5 id="startproc">startproc</h5>
|
||||
<p><code>startproc</code> starts a script, the output of the script is sent to the user or chat, user input will be sent back to the script. see <a href="3_advanced.md#Interactive-Chats">Advanced Usage</a></p>
|
||||
<p><em>usage:</em> startproc “script”</p>
|
||||
<p><em>example:</em></p>
|
||||
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="ex">startproc</span> <span class="st">'examples/calc.sh'</span></code></pre></div>
|
||||
<h5 id="checkproc">checkproc</h5>
|
||||
<p>Return true (0) if an interactive script is running in the chat.</p>
|
||||
<p><em>usage:</em> checkprog</p>
|
||||
<p><em>example:</em></p>
|
||||
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="ex">checkproc</span>
|
||||
<span class="kw">if</span><span class="bu"> [</span> <span class="st">"</span><span class="va">$res</span><span class="st">"</span> <span class="ot">-gt</span> 0<span class="bu"> ]</span> ; <span class="kw">then</span>
|
||||
<span class="ex">startproc</span> <span class="st">"examples/calc.sh"</span>
|
||||
<span class="kw">else</span>
|
||||
<span class="ex">send_normal_message</span> <span class="st">"</span><span class="va">${CHAT[ID]}</span><span class="st">"</span> <span class="st">"Calc already running ..."</span>
|
||||
<span class="kw">fi</span></code></pre></div>
|
||||
<h5 id="killproc">killproc</h5>
|
||||
<p>Kill the interactive script running in the chat</p>
|
||||
<p><em>usage:</em> killproc</p>
|
||||
<p><em>example:</em></p>
|
||||
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="ex">checkprog</span>
|
||||
<span class="kw">if</span><span class="bu"> [</span> <span class="st">"</span><span class="va">$res</span><span class="st">"</span> <span class="ot">-eq</span> 0<span class="bu"> ]</span>; <span class="kw">then</span>
|
||||
<span class="ex">killproc</span> <span class="kw">&&</span> <span class="ex">send_message</span> <span class="st">"</span><span class="va">${CHAT[ID]}</span><span class="st">"</span> <span class="st">"Command canceled."</span>
|
||||
<span class="kw">else</span>
|
||||
<span class="ex">send_message</span> <span class="st">"</span><span class="va">${CHAT[ID]}</span><span class="st">"</span> <span class="st">"Command is not running."</span>
|
||||
<span class="kw">fi</span></code></pre></div>
|
||||
<hr />
|
||||
<h5 id="background">background</h5>
|
||||
<p>Starts a script as a background job and attaches a jobname to it. All output from a background job is sent to the associated chat.</p>
|
||||
<p>In contrast to interactive chats, background jobs do not recieve user input and can run forever. In addition you can suspend and restart running jobs, e.g. after reboot.</p>
|
||||
<p><em>usage:</em> background “script” “jobname”</p>
|
||||
<p><em>example:</em></p>
|
||||
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="ex">background</span> <span class="st">"examples/notify.sh"</span> <span class="st">"notify"</span></code></pre></div>
|
||||
<h5 id="checkback">checkback</h5>
|
||||
<p>Return true (0) if an background job is active in the given chat.</p>
|
||||
<p><em>usage:</em> checkback “jobname”</p>
|
||||
<p><em>example:</em></p>
|
||||
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="ex">checkback</span> <span class="st">"notify"</span>
|
||||
<span class="kw">if</span><span class="bu"> [</span> <span class="st">"</span><span class="va">$res</span><span class="st">"</span> <span class="ot">-gt</span> 0<span class="bu"> ]</span> ; <span class="kw">then</span>
|
||||
<span class="ex">send_normal_message</span> <span class="st">"</span><span class="va">${CHAT[ID]}</span><span class="st">"</span> <span class="st">"Start notify"</span>
|
||||
<span class="ex">background</span> <span class="st">"examples/notify.sh"</span> <span class="st">"notify"</span>
|
||||
<span class="kw">else</span>
|
||||
<span class="ex">send_normal_message</span> <span class="st">"</span><span class="va">${CHAT[ID]}</span><span class="st">"</span> <span class="st">"Process notify already running."</span>
|
||||
<span class="kw">fi</span></code></pre></div>
|
||||
<h5 id="killback">killback</h5>
|
||||
<p><em>usage:</em> killback “jobname”</p>
|
||||
<p><em>example:</em></p>
|
||||
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="ex">checkback</span> <span class="st">"notify"</span>
|
||||
<span class="kw">if</span><span class="bu"> [</span> <span class="st">"</span><span class="va">$res</span><span class="st">"</span> <span class="ot">-eq</span> 0<span class="bu"> ]</span> ; <span class="kw">then</span>
|
||||
<span class="ex">send_normal_message</span> <span class="st">"</span><span class="va">${CHAT[ID]}</span><span class="st">"</span> <span class="st">"Kill notify"</span>
|
||||
<span class="ex">killback</span> <span class="st">"notify"</span>
|
||||
<span class="kw">else</span>
|
||||
<span class="ex">send_normal_message</span> <span class="st">"</span><span class="va">${CHAT[ID]}</span><span class="st">"</span> <span class="st">"Process notify not run."</span>
|
||||
<span class="kw">fi</span></code></pre></div>
|
||||
<hr />
|
||||
<h5 id="send_message">send_message</h5>
|
||||
<p><code>send_message</code> sends any type of message to the given chat. Type of output is steered by keywords within the message.</p>
|
||||
<p>The main use case for send_message is to process the output of interactive chats and background jobs. <strong>For regular Bot commands I recommend using of the dedicated send_xxx_message() functions from above.</strong></p>
|
||||
<p><em>usage:</em> send_message “${CHAT[ID]}” “message”</p>
|
||||
<p><em>example:</em> - see <a href="2_usage.md#send_message">Usage</a> and <a href="3_advanced.md#Interactive-Chats">Advanced Usage</a></p>
|
||||
<hr />
|
||||
<h3 id="helper-functions">Helper functions</h3>
|
||||
<h5 id="is_function-returns-true-if-the-given-function-exist-can-be-used-to-check-if-a-module-is-loaded.">_is_function Returns true if the given function exist, can be used to check if a module is loaded.</h5>
|
||||
<p><em>usage</em> _is_function function</p>
|
||||
<p><em>example:</em></p>
|
||||
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="ex">_is_function</span> <span class="st">"background"</span> <span class="kw">&&</span> <span class="ex">_message</span> <span class="st">"you can run background jobs!"</span></code></pre></div>
|
||||
<hr />
|
||||
<h3 id="bashbot-internal-functions">Bashbot internal functions</h3>
|
||||
<p>These functions are for internal use only and must not used in your bot commands.</p>
|
||||
<h5 id="get_file">get_file</h5>
|
||||
<p><em>usage:</em> url=“<span class="math inline">$(get_file "$</span>{CHAT[ID]}” “message”)"</p>
|
||||
<hr />
|
||||
<h5 id="send_text">send_text</h5>
|
||||
<p><em>usage:</em> send_text “${CHAT[ID]}” “message”</p>
|
||||
<hr />
|
||||
<h5 id="jsondecode">JsonDecode</h5>
|
||||
<p>Outputs decoded string to STDOUT</p>
|
||||
<p><em>usage:</em> JsonDecode “string”</p>
|
||||
<h5 id="jsongetstring">JsonGetString</h5>
|
||||
<p>Reads JSON fro STDIN and Outputs found String to STDOUT</p>
|
||||
<p><em>usage:</em> JsonGetString <code>"path","to","string"</code></p>
|
||||
<h5 id="jsongetvalue">JsonGetValue</h5>
|
||||
<p>Reads JSON fro STDIN and Outputs found Value to STDOUT</p>
|
||||
<p><em>usage:</em> JsonGetValue <code>"path","to","value"</code></p>
|
||||
<hr />
|
||||
<h5 id="get_chat_member_status">get_chat_member_status</h5>
|
||||
<p><em>usage:</em> get_chat_member_status “<span class="math inline">${CHAT[ID]}" "$</span>{USER[ID]}”</p>
|
||||
<p>this may get an official function …</p>
|
||||
<hr />
|
||||
<h5 id="process_client">process_client</h5>
|
||||
<p>Every Message sent to your Bot is processd by this function. It parse the send JSON and assign the found Values to bash variables.</p>
|
||||
<h5 id="process_updates">process_updates</h5>
|
||||
<p>If new updates are availible, this functions gets the JSON from Telegram and dispatch it.</p>
|
||||
<hr />
|
||||
<h5 id="getbotname">getBotName</h5>
|
||||
<p>The name of your bot is availible as bash variable “$ME”, there is no need to call this function if Bot is running.</p>
|
||||
<p><em>usage:</em> ME=“$(getBotNiname)”</p>
|
||||
<h5 id="inproc">inproc</h5>
|
||||
<p>Send Input from Telegram to waiting Interactive Chat.</p>
|
||||
<h4 id="prev-best-practice"><a href="5_practice.html">Prev Best Practice</a></h4>
|
||||
<h4 id="next-notes-for-developers"><a href="7_develop.html">Next Notes for Developers</a></h4>
|
||||
<h4 id="version-v0.70-pre1-7-g02d9afb"><br /><span class="math display"><em>V</em><em>E</em><em>R</em><em>S</em><em>I</em><em>O</em><em>N</em></span><br /> v0.70-pre1-7-g02d9afb</h4>
|
||||
</body>
|
||||
</html>
|
113
html/7_develop.html
Normal file
113
html/7_develop.html
Normal file
@ -0,0 +1,113 @@
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<meta http-equiv="Content-Style-Type" content="text/css" />
|
||||
<meta name="generator" content="pandoc" />
|
||||
<title>Bashobot Documentation - 7_develop.html</title>
|
||||
<style type="text/css">code{white-space: pre;}</style>
|
||||
<style type="text/css">
|
||||
div.sourceCode { overflow-x: auto; }
|
||||
table.sourceCode, tr.sourceCode, td.lineNumbers, td.sourceCode {
|
||||
margin: 0; padding: 0; vertical-align: baseline; border: none; }
|
||||
table.sourceCode { width: 100%; line-height: 100%; }
|
||||
td.lineNumbers { text-align: right; padding-right: 4px; padding-left: 4px; color: #aaaaaa; border-right: 1px solid #aaaaaa; }
|
||||
td.sourceCode { padding-left: 5px; }
|
||||
code > span.kw { color: #007020; font-weight: bold; } /* Keyword */
|
||||
code > span.dt { color: #902000; } /* DataType */
|
||||
code > span.dv { color: #40a070; } /* DecVal */
|
||||
code > span.bn { color: #40a070; } /* BaseN */
|
||||
code > span.fl { color: #40a070; } /* Float */
|
||||
code > span.ch { color: #4070a0; } /* Char */
|
||||
code > span.st { color: #4070a0; } /* String */
|
||||
code > span.co { color: #60a0b0; font-style: italic; } /* Comment */
|
||||
code > span.ot { color: #007020; } /* Other */
|
||||
code > span.al { color: #ff0000; font-weight: bold; } /* Alert */
|
||||
code > span.fu { color: #06287e; } /* Function */
|
||||
code > span.er { color: #ff0000; font-weight: bold; } /* Error */
|
||||
code > span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warning */
|
||||
code > span.cn { color: #880000; } /* Constant */
|
||||
code > span.sc { color: #4070a0; } /* SpecialChar */
|
||||
code > span.vs { color: #4070a0; } /* VerbatimString */
|
||||
code > span.ss { color: #bb6688; } /* SpecialString */
|
||||
code > span.im { } /* Import */
|
||||
code > span.va { color: #19177c; } /* Variable */
|
||||
code > span.cf { color: #007020; font-weight: bold; } /* ControlFlow */
|
||||
code > span.op { color: #666666; } /* Operator */
|
||||
code > span.bu { } /* BuiltIn */
|
||||
code > span.ex { } /* Extension */
|
||||
code > span.pp { color: #bc7a00; } /* Preprocessor */
|
||||
code > span.at { color: #7d9029; } /* Attribute */
|
||||
code > span.do { color: #ba2121; font-style: italic; } /* Documentation */
|
||||
code > span.an { color: #60a0b0; font-weight: bold; font-style: italic; } /* Annotation */
|
||||
code > span.cv { color: #60a0b0; font-weight: bold; font-style: italic; } /* CommentVar */
|
||||
code > span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Information */
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="header">
|
||||
<h1 class="title">Bashobot Documentation - 7_develop.html</h1>
|
||||
</div>
|
||||
<h4 id="home"><a href="../README.html">Home</a></h4>
|
||||
<h2 id="notes-for-bashbot-developers">Notes for bashbot developers</h2>
|
||||
<p>This section is about help and best practices for new bashbot developers. The main focus on is creating new versions of bashbot, not on develop your individual bot. Nevertheless the rules and tools described here can also help you with your bot development.</p>
|
||||
<p>bashbot development is done on github. If you want to provide fixes or new features <a href="https://help.github.com/en/articles/fork-a-repo">fork bashbot on githup</a> and provide changes as <a href="https://help.github.com/en/articles/creating-a-pull-request">pull request on github</a>.</p>
|
||||
<h3 id="setup-your-develop-environment">Setup your develop environment</h3>
|
||||
<ol style="list-style-type: decimal">
|
||||
<li>install git, install <a href="5_practice.md#Test-your-Bot-with-shellcheck">shellcheck</a></li>
|
||||
<li>setup your <a href="4_expert.md#Setting-up-your-Environment">environment for UTF-8</a></li>
|
||||
<li>clone your bashbot fork to a new directory <code>git clone https://github.com/<YOURNAME>/telegram-bot-bash.git</code>, replace <code><YOURNAME></code> with your username on github</li>
|
||||
<li>create and change to your develop branch <code>git checkout -b <YOURBRANCH></code>, replace <code><YOURBRANCH></code> with the name you want to name it, e.g. ‘develop’</li>
|
||||
<li>give your (dev) fork a new version tag: <code>git tag vx.xx</code>, version must be higher than current version</li>
|
||||
<li>setup github hooks by running <code>dev/install-hooks.sh</code> (optional)</li>
|
||||
</ol>
|
||||
<h3 id="test-add-push-changes">Test, Add, Push changes</h3>
|
||||
<p>A typical bashbot develop loop looks as follow:</p>
|
||||
<ol style="list-style-type: decimal">
|
||||
<li>start developing - <em>change, copy, edit bashbot files …</em></li>
|
||||
<li>after changing a bash sript: <code>shellcheck -x scipt.sh</code></li>
|
||||
<li><code>dev/all-tests.sh</code> - <em>in case if errors back to 2.</em></li>
|
||||
<li><code>dev/git-add.sh</code> - <em>check for changed files, update version string, run git add</em></li>
|
||||
<li><code>git commit' -m "COMMIT MESSAGE"; git push</code></li>
|
||||
</ol>
|
||||
<p><strong>If you setup iyou dev environment with hooks and use the scripts above, versioning, addding and testing is done automatically.</strong></p>
|
||||
<h3 id="prepare-a-new-version">Prepare a new version</h3>
|
||||
<p>After some development it may time to create a new version for the users. a new version can be in sub version upgrade, e.g. for fixes and smaller additions or a new release version for new features. To mark a new version use <code>git tag NEWVERSION</code> and run <code>dev/version.sh</code> to update all version strings.</p>
|
||||
<p>Usually I start with pre versions and when everything looks good I push out a release candidate (rc) and finally the new version.</p>
|
||||
<pre><code> v0.x-devx -> v0.x-prex -> v0.x-rc -> v0.x ... 0.x+1-dev ...</code></pre>
|
||||
<h3 id="versioning">Versioning</h3>
|
||||
<p>Bashbot is tagged with version numbers. If you start a new development cycle you must tag your fork with a version higher than the current version. E.g. if you fork ‘v0.60’ the next develop version should tagged as <code>git tag "v0.61-dev"</code> for fixes or <code>git tag "v0.70-dev"</code> for new features.</p>
|
||||
<p>To get the current version name of your develepment fork run <code>git describe --tags</code>. The output looks like <code>v0.70-dev-6-g3fb7796</code> where your version tag is followed by the number of commits since you tag your branch and followed by the latest commit hash. see also <a href="../dev/version.sh">comments in version.sh</a></p>
|
||||
<p>To update the Version Number in your scripts run <code>dev/version.sh</code>, it will update the line ‘#### <br /><span class="math display"><em>V</em><em>E</em><em>R</em><em>S</em><em>I</em><em>O</em><em>N</em></span><br /> ###’ in all files to the current version name.</p>
|
||||
<h3 id="shellchecking">Shellchecking</h3>
|
||||
<p>For a shell script running as a service it’s important to be paranoid about quoting, globbing and other common problems. So it’s a must to run shellchek on all shell scripts before you commit a change. this is automated by a git hook activated in Setup step 6.</p>
|
||||
<p>In addition you can run <code>dev/hooks/pre-commit.sh</code> every time you want to shellcheck all files given in ‘dev/shellcheck.files’.</p>
|
||||
<h2 id="bashbot-tests">bashbot tests</h2>
|
||||
<p>Starting with version 0.70 bashbot has a test suite. To start testsuite run <code>dev/all-tests.sh</code>. all-tests.sh will return ‘SUCCESS’ only if all tests pass.</p>
|
||||
<h3 id="enabling-disabling-tests">enabling / disabling tests</h3>
|
||||
<p>All tests are placed in the directory <code>test</code>. To disable a test remove the x flag from the ’*-test.sh’ test script, to (re)enable a test make the script executable again.</p>
|
||||
<h3 id="creating-new-tests">creating new tests</h3>
|
||||
<p>To create a new test run <code>test/ADD-test-new.sh</code> and answer the questions, afterwards you have the following described files and dirs:</p>
|
||||
<p>Each test consists of a script script named like <code>p-name-test.sh</code> <em>(where p is test pass ‘a-z’ and name the name of your test)</em> and an optional dir <code>p-name-test/</code> <em>(script name minus ‘.sh’)</em> for additional files.</p>
|
||||
<p>The file <code>ALL-tests.inc.sh</code> must be included from all tests, do not forget the shellcheck source directive to statisfy shellcheck.</p>
|
||||
<p>Tests with no dependency to other tests will run in pass ‘a’, tests which need an initialized bahsbot environment must run in pass ‘d’ or later. If ‘$1’ is present the script is started from ‘ALL-tests.sh’ and a temporary test environment is setup in directory ‘$1’. The temporary test environment is created when ‘ALL-tests.sh’ starts and deleted after all tests are finished.</p>
|
||||
<p>Example test</p>
|
||||
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="co">#!/usr/bin/env bash</span>
|
||||
<span class="co"># file: b-example-test.sh</span>
|
||||
|
||||
<span class="co"># include common functions and definitions</span>
|
||||
<span class="co"># shellcheck source=test/ALL-tests.inc.sh</span>
|
||||
<span class="bu">source</span> <span class="st">"./ALL-tests.inc.sh"</span>
|
||||
|
||||
<span class="kw">if</span><span class="bu"> [</span> <span class="ot">-f</span> <span class="st">"bashbot.sh"</span><span class="bu"> ]</span>; <span class="kw">then</span>
|
||||
<span class="bu">echo</span> <span class="st">"</span><span class="va">${SUCCESS}</span><span class="st"> bashbot.sh exist!"</span>
|
||||
<span class="bu">exit</span> 0
|
||||
<span class="kw">else</span>
|
||||
<span class="bu">echo</span> <span class="st">"</span><span class="va">${NOSUCCESS}</span><span class="st"> bashbot.sh missing!"</span>
|
||||
<span class="bu">exit</span> 1
|
||||
<span class="kw">fi</span></code></pre></div>
|
||||
<h4 id="prev-function-reference"><a href="6_function.html">Prev Function Reference</a></h4>
|
||||
<h4 id="next-bashbot-environment"><a href="8_custom.html">Next Bashbot Environment</a></h4>
|
||||
<h4 id="version-v0.70-pre1-7-g02d9afb"><br /><span class="math display"><em>V</em><em>E</em><em>R</em><em>S</em><em>I</em><em>O</em><em>N</em></span><br /> v0.70-pre1-7-g02d9afb</h4>
|
||||
</body>
|
||||
</html>
|
130
html/8_custom.html
Normal file
130
html/8_custom.html
Normal file
@ -0,0 +1,130 @@
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<meta http-equiv="Content-Style-Type" content="text/css" />
|
||||
<meta name="generator" content="pandoc" />
|
||||
<title>Bashobot Documentation - 8_custom.html</title>
|
||||
<style type="text/css">code{white-space: pre;}</style>
|
||||
<style type="text/css">
|
||||
div.sourceCode { overflow-x: auto; }
|
||||
table.sourceCode, tr.sourceCode, td.lineNumbers, td.sourceCode {
|
||||
margin: 0; padding: 0; vertical-align: baseline; border: none; }
|
||||
table.sourceCode { width: 100%; line-height: 100%; }
|
||||
td.lineNumbers { text-align: right; padding-right: 4px; padding-left: 4px; color: #aaaaaa; border-right: 1px solid #aaaaaa; }
|
||||
td.sourceCode { padding-left: 5px; }
|
||||
code > span.kw { color: #007020; font-weight: bold; } /* Keyword */
|
||||
code > span.dt { color: #902000; } /* DataType */
|
||||
code > span.dv { color: #40a070; } /* DecVal */
|
||||
code > span.bn { color: #40a070; } /* BaseN */
|
||||
code > span.fl { color: #40a070; } /* Float */
|
||||
code > span.ch { color: #4070a0; } /* Char */
|
||||
code > span.st { color: #4070a0; } /* String */
|
||||
code > span.co { color: #60a0b0; font-style: italic; } /* Comment */
|
||||
code > span.ot { color: #007020; } /* Other */
|
||||
code > span.al { color: #ff0000; font-weight: bold; } /* Alert */
|
||||
code > span.fu { color: #06287e; } /* Function */
|
||||
code > span.er { color: #ff0000; font-weight: bold; } /* Error */
|
||||
code > span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warning */
|
||||
code > span.cn { color: #880000; } /* Constant */
|
||||
code > span.sc { color: #4070a0; } /* SpecialChar */
|
||||
code > span.vs { color: #4070a0; } /* VerbatimString */
|
||||
code > span.ss { color: #bb6688; } /* SpecialString */
|
||||
code > span.im { } /* Import */
|
||||
code > span.va { color: #19177c; } /* Variable */
|
||||
code > span.cf { color: #007020; font-weight: bold; } /* ControlFlow */
|
||||
code > span.op { color: #666666; } /* Operator */
|
||||
code > span.bu { } /* BuiltIn */
|
||||
code > span.ex { } /* Extension */
|
||||
code > span.pp { color: #bc7a00; } /* Preprocessor */
|
||||
code > span.at { color: #7d9029; } /* Attribute */
|
||||
code > span.do { color: #ba2121; font-style: italic; } /* Documentation */
|
||||
code > span.an { color: #60a0b0; font-weight: bold; font-style: italic; } /* Annotation */
|
||||
code > span.cv { color: #60a0b0; font-weight: bold; font-style: italic; } /* CommentVar */
|
||||
code > span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Information */
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="header">
|
||||
<h1 class="title">Bashobot Documentation - 8_custom.html</h1>
|
||||
</div>
|
||||
<h4 id="home"><a href="../README.html">Home</a></h4>
|
||||
<h2 id="customize-bashbots-environment">Customize bashbots environment</h2>
|
||||
<p>This section describe how you can customize bashbot to your needs by setting environment variables.</p>
|
||||
<h3 id="change-file-locations">Change file locations</h3>
|
||||
<p>In standard setup bashbot is self containing, this means you can place ‘telegram-bot-bash’ any location and run it from there. All files - programm, config, data etc - will reside in ‘telegram-bot-bash’.</p>
|
||||
<p>If you want to have other locations for config, data etc, define and export the following environment variables. <strong>Note: all specified directories and files must exist or running ‘bashbot.sh’ will fail.</strong></p>
|
||||
<h4 id="bashbot_etc">BASHBOT_ETC</h4>
|
||||
<p>Location of the files <code>commands.sh</code>, <code>mycommands.sh</code>, <code>token</code>, <code>botadmin</code>, <code>botacl</code> …</p>
|
||||
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"> <span class="bu">unset</span> <span class="va">BASHBOT_ETC</span> <span class="co"># keep in telegram-bot-bash (default)</span>
|
||||
<span class="bu">export</span> <span class="va">BASHBOT_ETC</span> <span class="st">""</span> <span class="co"># keep in telegram-bot-bash</span>
|
||||
|
||||
<span class="bu">export</span> <span class="va">BASHBOT_ETC</span> <span class="st">"/etc/bashbot"</span> <span class="co"># unix like config location</span>
|
||||
|
||||
<span class="bu">export</span> <span class="va">BASHBOT_ETC</span> <span class="st">"/etc/bashbot/bot1"</span> <span class="co"># multibot configuration bot 1</span>
|
||||
<span class="bu">export</span> <span class="va">BASHBOT_ETC</span> <span class="st">"/etc/bashbot/bot2"</span> <span class="co"># multibot configuration bot 2</span></code></pre></div>
|
||||
<p>e.g. /etc/bashbot</p>
|
||||
<h4 id="bashbot_var">BASHBOT_VAR</h4>
|
||||
<p>Location of runtime data <code>data-bot-bash</code>, <code>count</code></p>
|
||||
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"> <span class="bu">unset</span> <span class="va">BASHBOT_VAR</span> <span class="co"># keep in telegram-bot-bash (default)</span>
|
||||
<span class="bu">export</span> <span class="va">BASHBOT_VAR</span> <span class="st">""</span> <span class="co"># keep in telegram-bot-bash</span>
|
||||
|
||||
<span class="bu">export</span> <span class="va">BASHBOT_VAR</span> <span class="st">"/var/spool/bashbot"</span> <span class="co"># unix like config location</span>
|
||||
|
||||
<span class="bu">export</span> <span class="va">BASHBOT_VAR</span> <span class="st">"/var/spool/bashbot/bot1"</span> <span class="co"># multibot configuration bot 1</span>
|
||||
<span class="bu">export</span> <span class="va">BASHBOT_VAR</span> <span class="st">"/var/spool/bashbot/bot2"</span> <span class="co"># multibot configuration bot 2</span></code></pre></div>
|
||||
<h4 id="bashbot_jsonsh">BASHBOT_JSONSH</h4>
|
||||
<p>Full path to JSON.sh script, default: ‘./JSON.sh/JSON.sh’, must end with ‘/JSON.sh’.</p>
|
||||
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"> <span class="bu">unset</span> <span class="va">BASHBOT_JSONSH</span> <span class="co"># telegram-bot-bash/JSON.sh/JSON.sh (default)</span>
|
||||
<span class="bu">export</span> <span class="va">BASHBOT_JSONSH</span> <span class="st">""</span> <span class="co"># telegram-bot-bash/JSON.sh/JSON.sh</span>
|
||||
|
||||
<span class="bu">export</span> <span class="va">BASHBOT_JSONSH</span> <span class="st">"/usr/local/bin/JSON.sh"</span> <span class="co"># installed in /usr/local/bin</span></code></pre></div>
|
||||
<h3 id="change-config-values">Change config values</h3>
|
||||
<h4 id="bashbot_decode">BASHBOT_DECODE</h4>
|
||||
<p>Bashbot offers two variants for decoding JSON UTF format to UTF-8. By default bashbot uses ‘json.encode’ if python is installed. If ‘BASHBOT_DECODE’ is set to any value (not undefined or not empty) the bash only implementation will be used.</p>
|
||||
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"> <span class="bu">unset</span> <span class="va">BASHBOT_DECODE</span> <span class="co"># autodetect python (default)</span>
|
||||
<span class="bu">export</span> <span class="va">BASHBOT_DECODE</span> <span class="st">""</span> <span class="co"># autodetect python</span>
|
||||
|
||||
<span class="bu">export</span> <span class="va">BASHBOT_DECODE</span> <span class="st">"yes"</span> <span class="co"># force internal</span>
|
||||
<span class="bu">export</span> <span class="va">BASHBOT_DECODE</span> <span class="st">"no"</span> <span class="co"># also force internal!</span></code></pre></div>
|
||||
<h4 id="bashbot_sleep">BASHBOT_SLEEP</h4>
|
||||
<p>Instead of polling permanently or with a fixed delay, bashbot offers a simple adaptive polling. If messages are recieved bashbot polls with no dealy. If no messages are availible bashbot add 100ms delay for every poll until the maximum of BASHBOT_SLEEP ms.</p>
|
||||
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"> <span class="bu">unset</span> <span class="va">BASHBOT_SLEEP</span> <span class="co"># 5000ms (default)</span>
|
||||
<span class="bu">export</span> <span class="va">BASHBOT_SLEEP</span> <span class="st">""</span> <span class="co"># 5000ms </span>
|
||||
|
||||
<span class="bu">export</span> <span class="va">BASHBOT_SLEEP</span> <span class="st">"1000"</span> <span class="co"># 1s maximum sleep </span>
|
||||
<span class="bu">export</span> <span class="va">BASHBOT_SLEEP</span> <span class="st">"10000"</span> <span class="co"># 10s maximum sleep</span>
|
||||
<span class="bu">export</span> <span class="va">BASHBOT_SLEEP</span> <span class="st">"1"</span> <span class="co"># values < 1000 disables sleep (not recommended) </span>
|
||||
</code></pre></div>
|
||||
<h3 id="testet-configs-as-of-v.07-release">Testet configs as of v.07 release</h3>
|
||||
<p><strong>Note: Environment variables are not stored, you must setup them before every call to bashbot.sh, e.g. from a script.</strong></p>
|
||||
<h4 id="simple-unix-like-config-for-one-bot.-bashbot-is-installed-in-usrlocaltelegram-bot-bash">simple Unix like config, for one bot. bashbot is installed in ‘/usr/local/telegram-bot-bash’</h4>
|
||||
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"> <span class="co"># Note: all dirs and files must exist!</span>
|
||||
<span class="bu">export</span> <span class="va">BASHBOT_ETC</span> <span class="st">"/etc/bashbot"</span>
|
||||
<span class="bu">export</span> <span class="va">BASHBOT_VAR</span> <span class="st">"/var/spool/bashbot"</span>
|
||||
|
||||
<span class="ex">/usr/local/telegram-bot-bash/bashbot.sh</span> start</code></pre></div>
|
||||
<h4 id="unix-like-config-for-one-bot.-bashbot.sh-is-installed-in-usrbin">Unix like config for one bot. bashbot.sh is installed in ‘/usr/bin’</h4>
|
||||
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"> <span class="co"># Note: all dirs and files must exist!</span>
|
||||
<span class="bu">export</span> <span class="va">BASHBOT_ETC</span> <span class="st">"/etc/bashbot"</span>
|
||||
<span class="bu">export</span> <span class="va">BASHBOT_VAR</span> <span class="st">"/var/spool/bashbot"</span>
|
||||
<span class="bu">export</span> <span class="va">BASHBOT_JSONSH</span> <span class="st">"/var/spool/bashbot"</span>
|
||||
|
||||
<span class="ex">/usr/local/bin/bashbot.sh</span> start</code></pre></div>
|
||||
<h4 id="simple-multibot-config-everything-is-keept-inside-telegram-bot-bash-dir">simple multibot config, everything is keept inside ‘telegram-bot-bash’ dir</h4>
|
||||
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"> <span class="co"># config for running Bot 1</span>
|
||||
<span class="co"># Note: all dirs and files must exist!</span>
|
||||
<span class="bu">export</span> <span class="va">BASHBOT_ETC</span> <span class="st">"./mybot1"</span>
|
||||
<span class="bu">export</span> <span class="va">BASHBOT_VAR</span> <span class="st">"./mybot1"</span>
|
||||
|
||||
<span class="ex">/usr/local/telegram-bot-bash/bashbot.sh</span> start</code></pre></div>
|
||||
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"> <span class="co"># config for running Bot 2</span>
|
||||
<span class="co"># Note: all dirs and files must exist!</span>
|
||||
<span class="bu">export</span> <span class="va">BASHBOT_ETC</span> <span class="st">"./mybot2"</span>
|
||||
<span class="bu">export</span> <span class="va">BASHBOT_VAR</span> <span class="st">"./mybot2"</span>
|
||||
|
||||
<span class="ex">/usr/local/telegram-bot-bash/bashbot.sh</span> start</code></pre></div>
|
||||
<h4 id="prev-notes-for-developers"><a href="7_develop.html">Prev Notes for Developers</a></h4>
|
||||
<h4 id="version-v0.70-pre1-0-g490c472"><br /><span class="math display"><em>V</em><em>E</em><em>R</em><em>S</em><em>I</em><em>O</em><em>N</em></span><br /> v0.70-pre1-0-g490c472</h4>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user