【问题标题】:Yowsup WhatsApp get phone numberYowsup WhatsApp 获取电话号码
【发布时间】:2014-04-03 10:14:18
【问题描述】:

我正在尝试了解如何将 Yowsup 库用于 WhatsApp。我可以发送消息并接收它,但我有兴趣获取电话号码以开始新的聊天。 换句话说,将开发一个可以与 WhatsApp 用户交互的计算机应用程序,目前我可以执行以下操作:

  1. 我通过以下命令获得了对 WhatsApp 服务器的访问权限:python yowsup-cli -c config.example --requestcode smspython yowsup-cli -c config.example --register xxx-xxx
  2. 我使用这个命令发送消息:python yowsup-cli -c config.example -s 39xxxxxxxxxx "!"
  3. 我可以使用以下命令进行交互式对话:python yowsup-cli -c config.example -i 39xxxxxxxxxx
  4. 使用以下命令获取我收到的所有消息:python yowsup-cli -c config.example -l

现在,当用户向我发送消息时,我如何与他/她互动?我想我应该从命令python yowsup-cli -c config.example -l 中获取电话号码,然后使用此命令开始新的交互式对话:python yowsup-cli -c config.example -i 39xxxxxxxxxx 其中 39xxxxxxxxxx 是我使用上一个命令获得的用户号码。 我希望你能帮助我

【问题讨论】:

    标签: python whatsapp


    【解决方案1】:

    我认为您不想将 yowsup-cli 用于开发目的。我认为它旨在成为一个功能非常有限的简单演示客户端。

    如果您查看yowsup-cli source code,您会发现它实际上导入了included examples 以提供命令行消息功能。

    您在这段代码中看到的是您的 python yowsup-cli -c config.example -l 实际调用了

    wa = WhatsappListenerClient(args['keepalive'], args['autoack'])
    wa.login(login, password)
    

    另一方面,此示例侦听器客户端具有注册到message_received 信号的回调函数。

    self.signalsInterface.registerListener("message_received", self.onMessageReceived)
    

    现在如果你仔细看看这个函数

    def onMessageReceived(self, messageId, jid, messageContent, timestamp, wantsReceipt, pushName, isBroadCast):
        formattedDate = datetime.datetime.fromtimestamp(timestamp).strftime('%d-%m-%Y %H:%M')
        print("%s [%s]:%s"%(jid, formattedDate, messageContent))
    
        if wantsReceipt and self.sendReceipts:
            self.methodsInterface.call("message_ack", (jid, messageId))
    

    您可以确定jid,因此您说您需要的电话号码在parameter list of this signal 上。如果您希望在用户向您发送消息后与用户进行交互,我猜您应该将 jid 或电话号码存储在您自己的订阅者中以获取此信号。

    简而言之 - 不要将 yowsup-cli 本身用于开发。使用它作为构建您自己的应用程序的起点。祝你好运!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-08-29
      • 2022-10-20
      • 1970-01-01
      • 2015-07-22
      • 2016-06-28
      • 2011-09-05
      • 1970-01-01
      相关资源
      最近更新 更多