【问题标题】:Telegram-cli : Script not sending messageTelegram-cli:脚本不发送消息
【发布时间】:2015-05-05 16:02:20
【问题描述】:

我正在使用 Telegram-cli 制作一个简单的 bash 脚本,我在其中发送 2 个参数(目标和消息),它应该向目标 (Name_FamilyName) 发送 Telegram 消息。

脚本如下:

#!/bin/bash
destination=$1;
message=$2;
  (echo "msg $destination $message"; echo "safe_quit") | bin/telegram-cli -k tg-server.pub -W

理论上,应该发送消息。我更改了脚本的权限,我用下一种方式调用它:

./script_send_message.sh Max_Musterman "Hola qute tal estas"

这就是我得到的输出:

Telegram-cli version 1.2.0, Copyright (C) 2013-2015 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.
Telegram-cli uses libtgl version 1.2.0
I: config dir=[/home/machine/.telegram-cli]
> msg Max_Musterman Hola qute tal estas
> safe_quit
User Max_Musterman updated username
User Max_Musterman online (was online [2015/04/09 06:56:04])
User Test Phone offline (was online [2015/04/09 06:51:42])
> > All done. Exit
halt

根本没有发送任何消息。 Insted,如果我从控制台发送完全相同的消息,它工作正常。这是我的工作:

bin/telegram-cli -k server.pub -W
Telegram-cli version 1.2.0, Copyright (C) 2013-2015 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.
Telegram-cli uses libtgl version 1.2.0
I: config dir=[/home/machine/.telegram-cli]
User Max_Musterman updated username
User Max_Musterman online (was online [2015/04/09 06:59:46])
User Max_Musterman offline (was online [2015/04/09 06:51:42])
> msg Max_Musterman Hola qute tal estas
[06:57]  Max_Musterman <<< Hola qute tal estas
User Max_Musterman marked read 1 outbox and 0 inbox messages
User Max_Musterman offline (was online [2015/04/09 06:57:29])
>

我的想法不多了。我开始认为,不知何故,在脚本中发送命令 msg 时未加载联系人列表,因此它什么也不发送(在控制台中,如果您向虚构的用户发送消息,它不会做任何事情就像在脚本中一样)。

有没有人经历过类似的事情?有什么解决办法吗?感谢您的帮助。

【问题讨论】:

    标签: linux bash telegram


    【解决方案1】:

    您还有其他选择:

    您可以使用“-e”选项和 user_id 代替管道命令到电报 cli:

    telegram-cli -RD -e "msg user#nnnnnnn Hola caracola"
    

    其中 nnnnn 是用户 ID。您可以通过“user_info .....”命令找到它。

    这样你就不用睡觉了,只需要让telegram-cli做所有的工作,不用-W命令telegram就不需要获取你所有的联系人。

    【讨论】:

    • -RD选项是什么意思?
    • 有时有效,但大多数时候会给出“FAIL: 38: can not parse arg #1”错误。不知道为什么。
    【解决方案2】:

    看起来当你从脚本运行 telegram_cli 时,它需要一些时间才能发送任何消息(直到它至少显示用户列表)。如果您在加载用户列表之前发送消息,您将无法发送任何内容。所以一个快速的解决方法(或者我们可以称之为顽皮的 hack)是告诉脚本等待 3 秒以发送消息:

    #!/bin/bash
    destination=$1;
    message=$2;
    (sleep 3;echo "msg $destination $message"; echo "safe_quit") | bin/telegram-cli -k tg-server.pub -W
    

    也许您必须将 sleep3 更改为 sleep 5 或类似的东西,但之后它应该能够发送消息。

    【讨论】:

      猜你喜欢
      • 2014-08-11
      • 1970-01-01
      • 2014-12-28
      • 2015-05-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多