1

目标:

我正在使用 Twilio 通过 SMS 向用户发送响应。然后我要求该用户再次通过 SMS 对响应进行评分。我想将用户的评分保存为响应模型的属性。

问题:

  • 我不知道如何以聪明的方式做到这一点。现在我能想到的最好的方法是找到发送给该用户的最新响应(用户可以有很多响应)并给它评分。但这有一些问题,例如,如果用户收到多个响应并想要对旧响应进行评分。

  • 我很绿色,我不知道如何实现代码。这就是我在相关控制器中的内容:

    class TwilioController < ApplicationController
    
      def process_sms
        @rating = params[:Body]
        #Find the response that this rating should get
        #Assign this rating to that response
        if @rating == "10"
          #thanks for the high rating
        else
          #will try to do better next time
        end
      end
    end
    

提前致谢,如果我能把这个问题做得更好,请告诉我——这是我第一次发帖。

4

1 回答 1

0

From the comments above:

1) I'm not sure how to turn that SMS into an attribute of the correct Response model

This would be the same as any Rails model - create a migration which adds the string to the model and run the migration. Then, a new attribute should be "settable" on the model.

2) I'm not sure how if there's a clever way to detect which Response the Rating corresponds to, since SMS doesn't have threading/replies/etc.

You should be able to use the REST API to get a list of SMS messages sent to your app from a given number. Unless your users can rate multiple responses at once, this should give you a list of replies from a specific user.

于 2016-08-25T17:51:20.133 回答