bashbot recover example

This commit is contained in:
Kay Marquardt (Gnadelwartz) 2020-07-12 13:52:03 +02:00
parent ef4d21f6f4
commit 78088d6472
4 changed files with 57 additions and 11 deletions

View File

@ -241,10 +241,10 @@ It features background tasks and interactive chats, and can serve as an interfac
<a class="sourceLine" id="cb5-3" title="3"><span class="bu">source</span> ./bashbot.sh source</a>
<a class="sourceLine" id="cb5-4" title="4"></a>
<a class="sourceLine" id="cb5-5" title="5"><span class="co"># send me a test message</span></a>
<a class="sourceLine" id="cb5-6" title="6"><span class="ex">send_message</span> <span class="st">&quot;</span><span class="va">$(</span><span class="fu">cat</span> <span class="st">&quot;</span><span class="va">$BOTADMIN</span><span class="st">&quot;</span><span class="va">)</span><span class="st">&quot;</span> <span class="st">&quot;test&quot;</span></a>
<a class="sourceLine" id="cb5-6" title="6"><span class="ex">send_message</span> <span class="st">&quot;</span><span class="va">$(</span><span class="ex">getConfigKey</span> <span class="st">&quot;botadmin&quot;</span><span class="va">)</span><span class="st">&quot;</span> <span class="st">&quot;test&quot;</span></a>
<a class="sourceLine" id="cb5-7" title="7"></a>
<a class="sourceLine" id="cb5-8" title="8"><span class="co"># send me output of a system command</span></a>
<a class="sourceLine" id="cb5-9" title="9"><span class="ex">send_message</span> <span class="st">&quot;</span><span class="op">$(&lt;</span><span class="st">&quot;</span><span class="va">$BOTADMIN</span><span class="st">&quot;</span><span class="op">)</span><span class="st">&quot;</span> <span class="st">&quot;</span><span class="va">$(</span><span class="fu">df</span> -h<span class="va">)</span><span class="st">&quot;</span></a></code></pre></div>
<a class="sourceLine" id="cb5-9" title="9"><span class="ex">send_message</span> <span class="st">&quot;</span><span class="va">$(</span><span class="ex">getConfigKey</span> <span class="st">&quot;botadmin&quot;</span><span class="va">)</span><span class="st">&quot;</span> <span class="st">&quot;</span><span class="va">$(</span><span class="fu">df</span> -h<span class="va">)</span><span class="st">&quot;</span></a></code></pre></div>
<p>For more information see <a href="doc/8_custom.md">Expert Use</a></p>
<h3>Blocked by telegram?</h3>
<p>This may happen if to many wrong requests are sent to api.telegram.org, e.g. using a wrong token or not existing API calls. If you have a fixed IP you can ask telegram service to unblock your ip or change your IP. If you are running a tor proxy on your server you may uncomment the <code>BASHBOT_CURL_ARGS</code> line in 'mycommands.sh'</p>
@ -254,9 +254,19 @@ It features background tasks and interactive chats, and can serve as an interfac
<a class="sourceLine" id="cb6-3" title="3"></a>
<a class="sourceLine" id="cb6-4" title="4"><span class="fu">wget</span> -t 1 -T 10 https://api.telegram.org/bot</a>
<a class="sourceLine" id="cb6-5" title="5"><span class="co">#Connecting to api.telegram.org (api.telegram.org)|46.38.243.234|:443... failed: Connection timed out.</span></a></code></pre></div>
<p>Since Version 0.98 bashbot can recover from broken connection to Telegram (aka blocked). therefore you must provide the function <code>bashbotBlockRecover()</code> in <code>mycommands.sh</code>. There you can check e.g. if your connection is working, change IP or simply wait some time.</p>
<p>If everything seems OK return 0 for retry or any non 0 value for abort.</p>
<div class="sourceCode" id="cb7"><pre class="sourceCode bash"><code class="sourceCode bash"><a class="sourceLine" id="cb7-1" title="1"><span class="co"># called when bashbot sedn command failed because we can not connect to telegram</span></a>
<a class="sourceLine" id="cb7-2" title="2"><span class="co"># return 0 to retry, return non 0 to give up</span></a>
<a class="sourceLine" id="cb7-3" title="3"><span class="fu">bashbotBlockRecover()</span> <span class="kw">{</span></a>
<a class="sourceLine" id="cb7-4" title="4"> <span class="co"># place your commands to unblock here, e.g. change IP or simply wait</span></a>
<a class="sourceLine" id="cb7-5" title="5"> <span class="fu">sleep</span> 60 <span class="kw">&amp;&amp;</span> <span class="bu">return</span> 0 <span class="co"># may be temporary</span></a>
<a class="sourceLine" id="cb7-6" title="6"> <span class="bu">return</span> 1 </a>
<a class="sourceLine" id="cb7-7" title="7"> <span class="kw">}</span></a>
<a class="sourceLine" id="cb7-8" title="8"></a></code></pre></div>
<p>@Gnadelwartz</p>
<h2>That's it!</h2>
<p>If you feel that there's something missing or if you found a bug, feel free to submit a pull request!</p>
<h4>$$VERSION$$ v0.98-0-g5b5447e</h4>
<h4>$$VERSION$$ v0.99-dev2-1-gef4d21f</h4>
</body>
</html>

View File

@ -213,10 +213,10 @@ export BASHBOT_HOME="$(pwd)"
source ./bashbot.sh source
# send me a test message
send_message "$(cat "$BOTADMIN")" "test"
send_message "$(getConfigKey "botadmin")" "test"
# send me output of a system command
send_message "$(<"$BOTADMIN")" "$(df -h)"
send_message "$(getConfigKey "botadmin")" "$(df -h)"
```
For more information see [Expert Use](doc/8_custom.md)
@ -233,10 +233,27 @@ wget -t 1 -T 10 https://api.telegram.org/bot
#Connecting to api.telegram.org (api.telegram.org)|46.38.243.234|:443... failed: Connection timed out.
```
Since Version 0.98 bashbot can recover from broken connection to Telegram (aka blocked). therefore you must provide the function
`bashbotBlockRecover()` in `mycommands.sh`. There you can check e.g. if your connection is working, change IP or simply wait some time.
If everything seems OK return 0 for retry or any non 0 value for abort.
```bash
# called when bashbot sedn command failed because we can not connect to telegram
# return 0 to retry, return non 0 to give up
bashbotBlockRecover() {
# place your commands to unblock here, e.g. change IP or simply wait
sleep 60 && return 0 # may be temporary
return 1
}
```
@Gnadelwartz
## That's it!
If you feel that there's something missing or if you found a bug, feel free to submit a pull request!
#### $$VERSION$$ v0.98-0-g5b5447e
#### $$VERSION$$ v0.99-dev2-1-gef4d21f

View File

@ -295,10 +295,10 @@ export BASHBOT_HOME="$(pwd)"
source ./bashbot.sh source
# send me a test message
send_message "$(cat "$BOTADMIN")" "test"
send_message "$(getConfigKey "botadmin")" "test"
# send me output of a system command
send_message "$(<"$BOTADMIN")" "$(df -h)"
send_message "$(getConfigKey "botadmin")" "$(df -h)"
```
For more information see [Expert Use](doc/8_custom.md)
@ -320,6 +320,25 @@ wget -t 1 -T 10 https://api.telegram.org/bot
failed: Connection timed out.
```
Since Version 0.98 bashbot can recover from broken connection to Telegram (aka
blocked). therefore you must provide the function
`bashbotBlockRecover()` in `mycommands.sh`. There you can check e.g. if your
connection is working, change IP or simply wait some time.
If everything seems OK return 0 for retry or any non 0 value for abort.
```bash
# called when bashbot sedn command failed because we can not connect to telegram
# return 0 to retry, return non 0 to give up
bashbotBlockRecover() {
# place your commands to unblock here, e.g. change IP or simply wait
sleep 60 && return 0 # may be temporary
return 1
}
```
@Gnadelwartz
## That's it!
@ -327,4 +346,4 @@ failed: Connection timed out.
If you feel that there's something missing or if you found a bug, feel free to
submit a pull request!
#### $$VERSION$$ v0.98-0-g5b5447e
#### $$VERSION$$ v0.99-dev2-1-gef4d21f

View File

@ -8,7 +8,7 @@
# #### if you start to develop your own bot, use the clean version of this file:
# #### mycommands.clean
#
#### $$VERSION$$ v0.99-dev2-0-g2b10471
#### $$VERSION$$ v0.99-dev2-1-gef4d21f
#
# uncomment the following lines to overwrite info and help messages
@ -251,7 +251,7 @@ else
# called when bashbot sedn command failed because we can not connect to telegram
# return 0 to retry, return non 0 to give up
bashbotBlockRecover() {
# place your commnds to unblock here, e.g. change IP or simply wait
# place your commands to unblock here, e.g. change IP or simply wait
sleep 60 && return 0 # may be temporary
return 1
}