/** * Endpoint which store a new lead with its lead source and forward the call * * @param Request $request Input data * @return Response Twiml to redirect call to the forwarding number */ public function store(Request $request) { $leadSource = LeadSource::where(['number' => $request->input('To')])->first(); $lead = new Lead(); $lead->leadSource()->associate($leadSource->id); $lead->city = $this->_normalizeName($request->input('FromCity')); $lead->state = $this->_normalizeName($request->input('FromState')); $lead->caller_number = $request->input('From'); $lead->caller_name = $request->input('CallerName'); $lead->call_sid = $request->input('CallSid'); $lead->save(); $forwardMessage = new Twiml(); $forwardMessage->dial($leadSource->forwarding_number); return response($forwardMessage, 201)->header('Content-Type', 'application/xml'); }
public function testSummaries() { // Given $fakeNumberOne = '+1153614723'; $fakeNumberTwo = '+1153619723'; $leadSourceOne = new LeadSource(['number' => '+1153614723', 'description' => 'Downtown south billboard', 'forwarding_number' => '+155005501']); $leadSourceTwo = new LeadSource(['number' => '+1153619723', 'description' => 'Downtown north billboard', 'forwarding_number' => '+155005502']); $leadSourceOne->save(); $leadSourceTwo->save(); $leadOne = new Lead(['caller_number' => '+148975933', 'city' => 'Some city', 'state' => 'Some state', 'caller_name' => 'John Doe', 'call_sid' => 'sup3runiq3']); $leadTwo = new Lead(['caller_number' => '+149824734', 'city' => 'Some other city', 'state' => 'Some state', 'caller_name' => 'John Doe', 'call_sid' => 'sup3runiq3']); $leadOne->leadSource()->associate($leadSourceOne->id); $leadOne->save(); $leadTwo->leadSource()->associate($leadSourceTwo->id); $leadTwo->save(); // When $responseByCity = $this->call('GET', route('lead.summary_by_city')); $responseByLeadSource = $this->call('GET', route('lead.summary_by_lead_source')); // Then $responseContentOne = json_decode($responseByCity->getContent(), true); $responseContentTwo = json_decode($responseByLeadSource->getContent(), true); $this->assertEquals([["lead_count" => 1, "city" => "Some other city"], ["lead_count" => 1, "city" => "Some city"]], $responseContentOne); $this->assertEquals([["lead_count" => 1, "description" => "Downtown south billboard", "number" => '+1153614723'], ["lead_count" => 1, "description" => "Downtown north billboard", "number" => '+1153619723']], $responseContentTwo); }