【问题标题】:How to get a user string input on Telepot?如何在 Telepot 上获取用户字符串输入?
【发布时间】:2017-03-31 20:11:47
【问题描述】:

我是 Python 和 Telegram bot 的新手,希望您能通过一个简单的示例帮助我理解这一点。 我需要的是定义一个方法,它返回一个字符串来完成一个 url。 在 Python 中我需要的是:

user = input("Insert a username to see the graph:")
graphUrl = "https://www.graphsss123.com/ser/graph/" + user + "-123.jpg"
print(graphUrl)

如何使用 Telepot 获得相同的结果?

谢谢

【问题讨论】:

    标签: python heroku telegram telegram-bot python-telegram-bot


    【解决方案1】:

    在 Telepot 中没有接收消息的专有功能(我猜!!),所以你必须维护状态(这里我使用 step 完成了)。下面的 sn-p 是添加 2 个数字的示例用户通过电报给出 参考:https://github.com/nickoala/telepot/issues/209

    global step, no1
            if step == 1:
                if msg['text'] == 'add':
                    bot.sendMessage(chat_id, "input no1")
                    step = 2
                else:
                    bot.sendMessage(chat_id, "please provide no")
            elif step == 2:
                no1 = msg['text']
                bot.sendMessage(chat_id, "input no2")
    
                step = 3
            elif step == 3:
                no2 = msg['text']
                no3=no1+no2
                bot.sendMessage(chat_id,no3)
                step = 1
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-30
      相关资源
      最近更新 更多