【发布时间】:2019-11-14 14:13:31
【问题描述】:
我正在使用 laravel 和 twilio 制作一个应用程序,以获取有关学生表现的反馈。逻辑如下。
- 一个用户,在我的例子中是学生(称为居民)登录并使用
用于向教师发送评估请求的网页表单(称为
参加)。此步骤开始一个会话并保存教师信息和
学生信息。
- 从数据库中挑选一个随机问题并将其保存到会话中。
- 教师的电话号码从数据库中提取,随机问题从会话中提取并使用 twilio 通过 SMS 发送给教师。
- 教师通过 Twilio SMS 以是、否或 DNS(未看到)响应。
- 教师的回答与学生姓名、教师姓名和提出的问题一起保存到数据库中。
我的应用程序一直运行到第 5 步。问题是当老师通过 SMS 回复时正在启动一个新会话。因此,响应后的所有内容都会保存到新会话中。我无法访问原始会话。我想我需要一种方法来自动授予教师对学生的访问权限(即用户帐户)。这似乎是第 3 方应用程序的问题。可以做到这一点还是有其他方法可以做到这一点? 下面是我用于响应的代码。它无法访问包含 residentName、firstQuestion 或 Attending_name 数据的会话。它为这些值设置 null 并将 null 上传到数据库。在这种情况下如何访问初始会话?
namespace App\Http\Controllers;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\Request;
use Session;
use Twilio\Rest\Client;
use Twilio\Twiml;
use App\Question;
use App\Answer;
class AskFirstQuestionsController extends Controller
{
public function qOneResponse(Request $request) {
$responderNumber = $request->input('From');
session()->put('responderNumber', $responderNumber);
session()->save();
$responderAnswer = strtolower($request->input('Body'));
$residentName = session::get('residentName');
$firstQuestion = session::get('first_question');
$attending_name = session::get('attending_name');
if (strpos($responderAnswer, 'yes') !== false) {
$answer = new
Answer(['attending'=>$attending_name,'resident_name'=>$residentName,'question_body'
=>$firstQuestion, 'answer_yes'=>1]);
$answer->save();
$smsResponse = "Great! Please help us reinforce this action by providing specific feedback
to the resident about what they did. Thank You for teaching!";
} else if (strpos($responderAnswer, 'no') !== false) {
$answer = new
answer::create(['attending'=>$attending_name,'resident_name'=>$resident_name,'question_body'
=>$firstQuestion, 'answer_no'=>1]);
$answer->save();
$smsResponse = "Ugh, ok...we will work on this. If you feel comfortable, please help us by
providing specific feedback to the resident about what they need to work on. Thank You for
teaching!";
} else if (strpos($responderAnswer, 'dns') !== false) {
$answer = new
answer::create(['attending'=>$attending_name,'resident_name'=>$resident_name,'question_body'
=>$firstQuestion, 'answer_dns'=>1]);
$answer->save();
$smsResponse = "How about trying a different question?";
} else {
$smsResponse = 'Please answer yes, no or dns.';
}
return response($this->respond($smsResponse))->header('Content-Type', 'application/xml');
}
public function respond($smsResponse) {
//get responderNumber and use it below
$responderNumber = session::get('responderNumber');
$response = new Twiml();
$response->message($smsResponse, ['to' => $responderNumber]);
return $response;
}
我是否需要采取某种类型的多重身份验证方法并以某种方式授予教师对学生帐户(用户帐户)的自动访问权限?或者我是否必须重新编写逻辑,以便响应请求生命周期关闭,然后尝试写入数据库(也许它会使用原始会话数据?)?或者有没有更简单的方法?请帮忙。我被困了一个多星期。
【问题讨论】:
-
如果两个学生同时把这个寄给同一个老师,你的计划是什么?
-
我想我可能需要为每个学生提供一个单独的电话号码,或者一种将发件人与收件人匹配的方法,但根据 Twilio 文档,这很难做到。但是,由于上述问题,我无法让它为单个学生工作。