Cómo convertir cualquier script en un bot de Telegram

Si necesita un simple bot de Telegram capaz de ejecutar scripts (escritos en cualquier idioma) y responder con texto e imágenes, entonces en cat. Allí encontrarás una historia sobre un motor de bot que hace lo que quieres.



Bot de Telegram



Una breve lista de características del motor:



  • El motor puede servir a varios bots a la vez
  • Bot ejecuta scripts (escritos en cualquier idioma)
  • , ( )
  • ( )
  • HTTP, , "" ( cron-)


: , IP-, SSL-… , . , , .



, .





Go. , root-. , , , , .



:



cd tmp
git clone https://github.com/michurin/cnbot.git
cd cnbot
go build ./cmd/...
./cnbot


( ) , . , .





, . : Telegram.



(config.yaml):



bots:
  firstBot:
    token: "22222222:AAAAAAAAAAAAAA"
    script: "/usr/bin/true"


( - , /bin/rm). (-i):



./cnbot -i -c config.yaml


, .



( -i)



./cnbot -c config.yaml


Telegram-.



user 500050880 is not allowed


user_id ( ),



bots:
  firstBot:
    token: "22222222:AAAAAAAAAAAAAA"
    script: "/bin/echo"
    allowed_users: [500050880]


, echo script. ( ) echo-. . hi, Hi!, -n hi.



(-n echo). : ; , , , ; .



. /bin/echo :



#!/bin/sh
env


Hello!



BOT_TEXT=Hello!
BOT_FROM_FIRSTNAME=Alexey
BOT_NAME=firstBot
BOT_CHAT=500050880
BOT_FROM=500050880


, , ID , , ( ; , ).



, . , white list . ID — . . demo.sh.



, PATH . , .





#!/bin/sh
echo '%!PRE'
env | sort


. markdown, . demo.sh.



, stdout:



#!/bin/sh
curl -qfs https://golang.org/lib/godoc/images/footer-gopher.jpg


, "empty", , "".



demo-, .





HTTP bind_address :



bots:
  firstBot:
    token: "22222222:AAAAAAAAAAAAAA"
    script: "/bin/echo"
    allowed_users: [500050880]
    bind_address: ":9091"


:



echo "ok" | curl -qfsX POST --data-binary @- "http://:9091/500050880"


, , . , output . , .



multipart/form-data:



curl -qfsX POST -F to=500050880 -F msg=ok "http://:9091"


, . , , . , demo-. http- . readme , , , .



, , — .



!



...



..., , .



- . , . , , . , . .



, . : , , VPN, … , , - , .



, , , Telegram API . - bash+curl+jq, , .



. . , , - .



, . (), … , , . , , , .



2018 Go , , Go. :-) , , Go . , Go, Go, "" ( ).



. cnbot, .



?



, . . - , — . .



Pero me gustaría desarrollar el motor hacia la incrustabilidad: destacar alguna parte simple de él que podría conectarse mediante una biblioteca a cualquier programa de Go. Convencionalmente, si ya tiene un microservicio para ... para qué sirve ... incluso para renderizar escenas 3D, puede incrustar un chat de bot en él en una o dos líneas para diagnóstico / monitoreo / control operativo ... Esto, me parece, sería útil. De hecho, puede hacerlo ahora. Simplemente no es muy conveniente.




All Articles