简体   繁体   English

Twilio短信回复功能

[英]Twilio sms reply feature

I've created a system based on cron job which generates new tasks for user. 我已经创建了一个基于cron作业的系统,可以为用户生成新任务。 When new task is generated cron file sends a sms to user using twilio sms api. 生成新任务时,cron文件使用twilio sms api向用户发送短信。 Now I want make something like when user reply to that sms with word "Done" that task associated with sms will be completed in my database. 现在我想做一些事情,比如当用户用“Done”字样回复短信时,与我的数据库相关的任务将在我的数据库中完成。

I've set reply URL in twilio account. 我在twilio帐户中设置了回复网址。 And everything is working fine. 一切都很好。 My point is how can I complete that task in database. 我的观点是如何在数据库中完成该任务。 Is there any feature exist in twilio that can help me to send extra parameter as task id, so that I can fetch that id from reply and update the status of task. twilio中是否存在任何可以帮助我发送额外参数作为任务ID的功能,以便我可以从回复中获取该ID并更新任务的状态。

Twilio developer evangelist here. Twilio开发者传道者在这里。

There's no way in SMS to reply to a specific message (try it yourself in your SMS app on your phone), so there's no ID that you can pass around secretly within conversations. 短信无法回复特定消息(在手机上的短信应用中自行尝试),因此没有可以在对话中秘密传递的ID。

There are a few ways you can work around this. 有几种方法可以解决这个问题。

If the user is sent only one task at a time, then you can record what their current task is and when you receive the message saying "done" tick that one off and send them the next task. 如果用户一次只发送一个任务,那么您可以记录他们当前的任务是什么,以及何时收到消息“完成”勾选一个任务并向他们发送下一个任务。

You could send them a task ID within the message, and tell them to include that ID when they respond to say they are done. 您可以在邮件中向他们发送任务ID,并在他们回复时告诉他们包含该ID,说明他们已完成。 You could then parse the ID out of the message and mark it as done in your database. 然后,您可以从消息中解析ID,并在数据库中将其标记为已完成。

Or, and this might be too far, you could use a pool of numbers to send tasks out such that each live task for a user has a unique number the user responds to. 或者,这可能太过分了,您可以使用一个数字池来发送任务,以便用户的每个实时任务都有一个用户响应的唯一编号。 Then you can look up the task based on the user and the number they replied to. 然后,您可以根据用户和他们回复的号码查找任务。 Then you can free up the number for a new task. 然后,您可以释放新任务的号码。

Let me know if this helps at all. 如果这有帮助,请告诉我。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM