<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>Tg on Karpoke - Just Another Blog</title><link>http://karpoke.ignaciocano.com/tags/tg/</link><description>Recent content in Tg on Karpoke - Just Another Blog</description><generator>Hugo -- 0.159.0</generator><language>es</language><lastBuildDate>Sat, 31 May 2014 13:27:00 +0100</lastBuildDate><atom:link href="http://karpoke.ignaciocano.com/tags/tg/index.xml" rel="self" type="application/rss+xml"/><item><title>Enviar y reicibir notificaciones de Telegram desde la línea de comandos</title><link>http://karpoke.ignaciocano.com/2014/05/31/enviar-y-reicibir-notificaciones-de-telegram-desde-la-linea-de-comandos/</link><pubDate>Sat, 31 May 2014 13:27:00 +0100</pubDate><guid>http://karpoke.ignaciocano.com/2014/05/31/enviar-y-reicibir-notificaciones-de-telegram-desde-la-linea-de-comandos/</guid><description>&lt;p&gt;Utilizando &lt;a href="http://github.com/vysheng/tg"&gt;tg&lt;/a&gt;, podemos enviar y recibir mensajes de nuestros
contactos en Telegram, incluyéndonos a nosotros mismos, desde el
terminal.&lt;/p&gt;
&lt;h2 id="envíos-programados"&gt;Envíos programados&lt;/h2&gt;
&lt;p&gt;Combinándolo con &lt;code&gt;expect&lt;/code&gt;, conseguiremos una forma sencilla de programar
notificaciones.&lt;/p&gt;
&lt;p&gt;He aquí un pequeño ejemplo:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;#!/usr/bin/env bash
&lt;/code&gt;&lt;/pre&gt;&lt;pre tabindex="0"&gt;&lt;code&gt;function tg {
# First argument, if any, must be the receiver
local to=&amp;#34;$1&amp;#34;
local msg=&amp;#34;&amp;#34;
local cmd=&amp;#34;&amp;#34;
if [ $# -gt 1 ]; then
shift 1
msg=&amp;#34;$@&amp;#34;
else
while read line; do
if [ -z &amp;#34;$msg&amp;#34; ]; then
msg=$line
else
msg=&amp;#34;$msg\n$line&amp;#34;
fi
done
if [ -z &amp;#34;$to&amp;#34; ]; then
to=$(awk &amp;#39;{print $1}&amp;#39; &amp;lt;&amp;lt;&amp;lt; $msg)
msg=$(awk &amp;#39;{$1=&amp;#34;&amp;#34;;print $0}&amp;#39; &amp;lt;&amp;lt;&amp;lt; $msg)
fi
fi
if [[ $msg =~ &amp;#34;\n&amp;#34; ]]; then
file=$(mktemp)
echo -e &amp;#34;$msg&amp;#34; &amp;gt; $file
cmd=&amp;#34;send_text $to $file&amp;#34;
else
cmd=&amp;#34;msg $to $msg&amp;#34;
fi
#echo $cmd
expect -c &amp;#34;
log_user 0
match_max 100000
spawn /path/to/telegram -k /path/to/tg-server.pub
expect \&amp;#34;User \&amp;#34;
send -- \&amp;#34;$cmd\r\&amp;#34;
expect \&amp;#34;Sent\&amp;#34;
send \&amp;#34;quit\&amp;#34;
&amp;#34;
}
tg $@
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Algunos ejemplos de uso:&lt;/p&gt;</description></item></channel></rss>