Php 如何通过twilio管理来自webapp的短信和回复
我正在使用Laravel5.1和twilio创建一个消息传递web应用程序,我正在使用这个包 已在twilio仪表板中完成设置和配置Php 如何通过twilio管理来自webapp的短信和回复,php,laravel,laravel-5.1,twilio,twilio-php,Php,Laravel,Laravel 5.1,Twilio,Twilio Php,我正在使用Laravel5.1和twilio创建一个消息传递web应用程序,我正在使用这个包 已在twilio仪表板中完成设置和配置 在可编程SMS部分,i'hv创建了一个带有副驾驶的消息服务,其中包括一个电话号码((xxx)xxx) 给定入站请求url 我的laravel应用程序代码 我有一个简单的用户对用户的消息传递,其中两个用户都在线,与twilio无关。但是假设一个用户离线,另一个在线,在线用户向离线用户发送聊天信息,那么我必须通过twilo通过短信通知离线用户的电话号码 pub
public static function notifyOfflineUser($user,$reply_text){
$message = "Mysite: ".$user->user_from->firstname.", '".strip_tags($reply_text)."' Reply via mysite ".url('general-message')." or SMS";
if($user->profile->mobile) {
try {
\Twilio::message($user->profile->mobile, $message);
} catch (\Exception $e) {
}
}
}
它通过twilio电话号码向用户发送短信
用户可从其手机回复此信息至此号码。
如果回复成功,我必须将信息添加到在线用户的留言板上
//Inbound request url routed to this url with From number, body and other data.
public function smsReply(Request $request){
$user_id_to = Profile::where('mobile', $request->get('From'))->first(['user_id'])->user_id;
$body = $request->get('Body');
$user_id_from = Message::where('user_id_to', $user_id_to)->orderBy('id', 'desc')->first()->user_id_from;
//dd($request->all());
$message = new Message();
$message->user_id_from = $user_id_to;
$message->user_id_to = $user_id_from;
$message->message = $body;
$message->save();
return response()->json(true);
}
现在,如果多个在线用户向该离线用户发送聊天信息,离线用户将从同一个twilio号码收到多条短信,并且所有短信都在同一个堆栈中,这意味着如果他/她回复将发送到同一号码的短信,则不会收到不同的短信,所有在线用户都会在留言板上添加相同的信息
//Inbound request url routed to this url with From number, body and other data.
public function smsReply(Request $request){
$user_id_to = Profile::where('mobile', $request->get('From'))->first(['user_id'])->user_id;
$body = $request->get('Body');
$user_id_from = Message::where('user_id_to', $user_id_to)->orderBy('id', 'desc')->first()->user_id_from;
//dd($request->all());
$message = new Message();
$message->user_id_from = $user_id_to;
$message->user_id_to = $user_id_from;
$message->message = $body;
$message->save();
return response()->json(true);
}
现在我的问题是
是否还需要从twilio中获取其他信息,如多个号码、短代码、tollfree,或者我必须使用我的laravel代码,以便我可以将每条短信作为不同的短信发送到脱机用户的手机,以便我可以将它们与入站请求url区分开来?请随时询问我是否需要更多信息。这里是Twilio开发者福音传道者 为了能够处理这样的多个对话,你需要多个号码。这样,一个数字就可以表示两个用户之间的关系,并且你可以知道用户在响应什么
我建议您查看此项了解更多信息。我需要多少号码?在离线时,100%的用户可以向他/她发送聊天信息,所以我需要100个或更多号码吗?您需要的号码与用户之间关系的最大数量相同。查看本文了解详细信息:您不需要这两个。您只需要足够的数字来覆盖用户可以进行的最大对话数。请注意,一旦与您完成对话,您就可以重用某个号码或将其释放。