我正在创建一个接受咖啡订单的电报机器人。它还与IBM Watson Assistant集成在一起。问题是,当我尝试使用update.message.reply_text(msg)
通过python将消息发送到电报时-仅当我从watson获取响应时才起作用,但是如果我直接从python指定文本,则该文本不会显示给电报。但是我能够通过python为/ start和/ help发送硬编码文本。
Library-python-telegram-bot
def message(bot, update):
print('Received an update')
global context
global conversation
conversation= ConversationV1(username='username',
password='password',
version='2018-02-16')
# get response from watson
response = conversation.message(
workspace_id='id',
input={'text': update.message.text},
context=context)
#print(json.dumps(response, indent=2))
context = response['context']
order=response['entities']
print(order)
if len(order)%2 == 0 and len(order)%3==0:
t=0
for j in range(len(order)):
if order[j]['entity']=='types':
t+=1
print(t)
if (len(order)/t)%3==0:
handle_three(order)
elif (len(order)/t)%2==0:
handle_two(order)
elif len(order)%3 ==0:
handle_three(order)
elif len(order)%2==0:
handle_two(order)
elif len(order) == 1 and order[0]['entity'] == 'types':
data.append({'type':order[0]['value']})
else:
#Fetch response from watson and display
resp2 = send_tele(response)
update.message.reply_text(resp2)
i=0
while i<len(data):
d=data[i].copy()
print(d)
if 'size' in d and 'type' in d and 'number' in d:
print(response['entities'])
i=i+1
if 'number' not in d and 'size' not in d and 'type' in d:
res='Python: How many cups of '+d[type]+' would you like to have?'
print(res)
#The below line
**update.message.reply_text(res)**
if len(order) == 1 and order[0]['entity'] == 'number':
print(order)
d.update({'number':order[0]['value']})
data[i]=d
print(data)
i=i+1
我在粗体代码部分遇到了问题。如果我从Watson那里获取响应,它会起作用。请让我知道我做错了。谢谢。