【发布时间】:2018-07-04 08:58:13
【问题描述】:
Twilio 的新手,已成功跟踪 SMS Python Quickstart guide,并将两个位组合在一起,但现在有一些冗余代码,我似乎无法在不出错的情况下摆脱它们。
我有 Python 代码,它从文本消息中获取坐标,将其转换为 Google 地图链接,然后将该链接发送到不同的电话号码。
但是,目前它也在向原始发件人电话号码发送此回复,因为这是您设置的原始指南。
我只希望它把消息发送到指定的号码,而不是回复原发件人。
运行.py:
# /usr/bin/env python
# Download the twilio-python library from twilio.com/docs/libraries/python
from flask import Flask, request
from twilio.twiml.messaging_response import MessagingResponse
# Download the helper library from https://www.twilio.com/docs/python/install
from twilio.rest import Client
# Your Account Sid and Auth Token from twilio.com/console
account_sid = 'account_sid'
auth_token = 'auth_token'
client = Client(account_sid, auth_token)
app = Flask(__name__)
@app.route("/", methods=['GET', 'POST'])
def sms_reply():
messages = client.messages.list()
print(messages[0].body)
coord = messages[0].body
lat,lon = coord.split(":")
mapURL = "https://www.google.com/maps/search/?api=1&query=" + lat + "," + lon
message = client.messages.create(
body=mapURL,
from_='+442030954643',
to='+447445678954'
)
"""Respond to incoming messages with a friendly SMS."""
# Start our response
resp = MessagingResponse()
# Add a message
resp.message(mapURL)
return str(resp)
if __name__ == "__main__":
app.run(debug=True)
每当我删除我认为与向发件人回复消息有关的行时,它似乎破坏了我仍然需要的其他一些行。
非常感谢任何帮助,谢谢!
【问题讨论】: