comm = $comm; } public function handle() { $auth = env('INTERAKT_API_AUTH', 'Basic S1BnVWoxRGZUcWpTYVl2OG9ZN3lEbkk2YjlXTzUtZXhvOWpMQ3RIN3ZJVTo='); $sends = DB::table('raphiwa_send')->where('is_sent', 0)->limit(30)->get(); if ($sends->count() > 0) { foreach ($sends as $send) { $resp = Http::withHeaders(['Authorization' => $auth]) ->post('https://api.interakt.ai/v1/public/message/', (array) json_decode($send->text)); $respj = json_decode($resp->getBody()); print_r($respj); if ($respj->result) { DB::table('raphiwa_send')->where('id', $send->id)->update([ 'is_sent' => 1, 'response' => $resp->getBody(), 'updated_at' => now(), ]); } else { DB::table('raphiwa_send')->where('id', $send->id)->update([ 'is_sent' => 1, 'response' => $resp->getBody(), 'updated_at' => now(), 'status' => 0, ]); } } } else { $sends = DB::table('message_send as ms') ->leftJoin('sessions as s', 'ms.session_id', '=', 's.id') ->leftJoin('message_template as t', 'ms.template', '=', 't.id') ->where('ms.status', 'active') ->select( 'ms.id', 'ms.session_id', 's.code', 's.type', 's.number', 's.start_date', 's.venue', 's.communication_mode', 't.template_code', 't.template_body', 't.title as template_title', 'ms.header_params', 'ms.body_params', 'ms.button_params', 'ms.audience' ) ->limit(5) ->get(); if ($sends->count() > 0) { foreach ($sends as $send) { print_r($send); $searchparam = ['session_code' => $send->code]; if ($send->audience == 'attended') { $searchparam['present'] = 'yes'; } $response = LambdaRequest::getrequest( 'contact', 'contact/get_all', [ 'source' => 'dynamodb', 'search' => json_encode($searchparam), 'fields' => json_encode(['session_code', 'email', 'name', 'phone', 'id']), ], env('LAMBDA_ACCESS_TOKEN', 'default_value') ); if (sizeof($response->data->items) > 0) { $config = [ 'id' => $send->id, 'template_code' => $send->template_code, 'template_body' => $send->template_body, 'template_title' => $send->template_title, 'header_params' => $send->header_params, 'body_params' => $send->body_params, 'button_params' => $send->button_params, ]; foreach ($response->data->items as $item) { $this->comm->dispatchForContact($send, $item, $config); } } DB::table('message_send')->where('id', $send->id)->update(['status' => 'send']); } } } return 0; } }