需要电报机器人来编辑另一个文件的函数
如标题所说。我需要我的电报机器人来获取用户输入,并使用它来从另一个文件上更改另一个函数的值。我已经让文件从机器人成功运行,但是我不知道如何首先更改值。我正在使用python-telegram-bot。
这是我需要编辑的代码,该代码在一个单独的文件(call.py)中,
call = client.calls.create(
machine_detection='Enable',
url='https://ngrok.io/main',
to='',
from_=''
)
我需要在上面的代码中编辑“ to”和“ from”“ from”“ from”字段。 我用来从机器人运行此操作的代码如下:
def update(update, context):
update.message.reply_text('Enter number :\n'
'e.g. 18004585478\n')
update.message.reply_text('Calling...')
exec(open("call.py").read())
我对所有这些都是新的,所以我知道代码根本不好。我读到我应该使用对话手或指挥手,但老实说,我不确定如何实施它。
我根据Alexey建议的内容编辑了代码,现在AM卡在类似问题上。
def update(update, context):
update.message.reply_text('Enter number:\n'
'e.g. 18004585478\n'
'Number Must begin with 1')
from_number = update.message.text
update.message.reply_text('Enter number:\n'
'e.g. 18004585478\n'
'Number Must begin with 1')
to_number = update.message.text
update.message.reply_text('Calling...')
call_state = call.make_call(to_number, from_number)
Telegram Bot仅一次运行所有代码,它不会停止并等待数字字段中的任何输入。我该如何实现MessageHandler以使Bot停止并接受输入以传递到Call_State,然后在末尾执行CALL_STATE?
As the title says. I need my telegram bot to take user input, and use that to change some values on another function from another file. I already got the file to be successfully run from the bot, but I can't figure out how to change values first. I am using Python-Telegram-bot.
here is the code I need to edit that is in a separate file (call.py)
call = client.calls.create(
machine_detection='Enable',
url='https://ngrok.io/main',
to='',
from_=''
)
I need to edit the "to" and "from" field(s) in this code above.
The code I use to run this from my bot is as follows:
def update(update, context):
update.message.reply_text('Enter number :\n'
'e.g. 18004585478\n')
update.message.reply_text('Calling...')
exec(open("call.py").read())
I am pretty new to all this so I know the code is not good at all. I have read that I should be using ConversationHandler or CommandHandler but I honestly am not sure how to implement it.
I edited the code based on what Alexey suggested and now am stuck on a similar issue.
def update(update, context):
update.message.reply_text('Enter number:\n'
'e.g. 18004585478\n'
'Number Must begin with 1')
from_number = update.message.text
update.message.reply_text('Enter number:\n'
'e.g. 18004585478\n'
'Number Must begin with 1')
to_number = update.message.text
update.message.reply_text('Calling...')
call_state = call.make_call(to_number, from_number)
The Telegram bot just runs all the code at once, it doesn't stop and wait for any input from the number fields. How do I go about implementing MessageHandler to make the bot stop and accept input to pass along to call_state, then execute call_state at the end?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您无需更改代码,您需要使用参数传递想要的数据。
在
call.py
中,您可以在
更新
功能中制作一个funcitonYou don't need to change the code, you need to use arguments to pass the data you wanted to.
In
call.py
you can make a funcitonIn your
update
function just use the function by giving it the necessary valuesAlexey所说的最终进行了非常轻微的修改。
我采用了Alexey发布的内容并删除了数字,并将它们变成了我可以从其他脚本中编辑的变量。
然后,在另一个文件中,我通过使用
user_data [from] = update.message.text.text
和user_data [to] = update来导入所需编辑的文件来定义变量并执行它们。 Message.Text
。然后打电话给funciton。
call_state = call.make_call({user_data [to]},{user_data [from]})
不要忘记在代码顶部添加
user_data = {}
。What Alexey stated ended up working with very slight modifications.
I took what Alexey posted and deleted the numbers and turned them into a variable I could edit from my other script.
Then in the other file I defined the variables and executed them by importing the file I needed to edit by using
user_data[FROM] = update.message.text
and user_data[TO] = update.message.text
.then calling the funciton.
call_state = call.make_call({user_data[TO]}, {user_data[FROM]})
Dont forget to add
user_data = {}
at the top of your code.