微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用脚本将字符串传递给linux cli交互式程序

我正在使用一个库来通过bash linux ubuntu中的命令行访问电报.
这是电报-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-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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐