我正在使用一个库在 bash linux ubuntu 中通过命令行访问 Telegram 。 这是 Telegram -cli。 引用 https://github.com/vysheng/tg
这是一个交互式程序,可以通过以下方式启动
./bin/telegram-cli -k tg-server.pub
它输出这些行:
Telegram-cli version 1.1.1, Copyright (C) 2013-2014 Vitaly Valtman
Telegram-cli comes with ABSOLUTELY NO WARRANTY; for details type `show_license'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show_license' for details.
I: config dir=[/home/utonto/.telegram-cli]
>
用“>”提示。 要发送消息,在此提示符下您必须键入
msg USERNAME This is a test message
我想在我的电脑上运行一个脚本,告诉我工作时的室温。 我怎样才能做到这一点? 我搜索了 SO 并发现了类似的问题。 建议使用“expect”命令,我这样做了但没有用。也许 - 当然 - 因为我是初学者。 我也试过了
echo "msg USERNAME this is a message |
telegram-cli -k ......"
但是没有用。 据您所知,在我的安卓系统上,我有一个用于 Telegram 的电话号码,但我使用另一部手机注册了 Telegram -cli。 有人可以帮助我吗?
最佳答案
参见此处:remote control with Telegram
为了拦截新的传入消息,我们创建了一个文件 action.lua
"Lua is a powerful, fast, lightweight, embeddable scripting language.
Lua combines simple procedural syntax with powerful data description constructs based on associative arrays and extensible semantics. Lua is dynamically typed, runs by interpreting bytecode for a register-based virtual machine, and has automatic memory management with incremental garbage collection, making it ideal for configuration, scripting, and rapid prototyping."
来自 http://www.lua.org .
sudo nano /home/pi/tg/action.lua
有这个内容
function on_msg_receive (msg)
if msg.out then
return
end
if (msg.text=='ping') then
send_msg (msg.from.print_name, 'pong', ok_cb, false)
end
end
function on_our_id (id)
end
function on_secret_chat_created (peer)
end
function on_user_update (user)
end
function on_chat_update (user)
end
function on_get_difference_end ()
end
function on_binlog_replay_end ()
end
保存并退出,当收到的短信是“ping”时,Telegram 回复我们一条包含“pong”的短信。
move in tg
cd /home/pi/tg
然后输入
bin/telegram-cli -k tg-server.pub -W -s action.lua
关于linux - 使用脚本将字符串传递给 linux cli 交互式程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27671801/