how to send push notification from laravel to expo app - laravel

I need someone to tell me how to send notifications from laravel to expo, I searched in the internet I did not understand, and I don't know how to send a notification for push token generated by expo

The easies way I found was to just use the post API provided by expo
I just created a service class
<?php
namespace App\Http\Services;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Log;
class ExpoService
{
public function sendPushNotification($recipients,$title,$body){
$response = Http::post("https://exp.host/--/api/v2/push/send",[
"to" => $recipients ,
"title"=>$title,
"body"=> $body
])->json();
Log::info($response);
}
}
$recipients is an array of tokens

Related

How to get parameter value from dialogflow with botman

I tried to call intent in dialogflow. My intent is detect geo-city from message. This is my dialogflow page. My problem is when I run the application and send message in botman it doesn't send me the geo-city value.
I tried send in botman 'My city is colombo' but no any responce or reply in botman.
I setup my api json file in .env file
GOOGLE_CLOUD_PROJECT="project_id"
GOOGLE_APPLICATION_CREDENTIALS="pathtojsonfile"
In dialogflow::create() function did I call the security key correctly?
<?php
namespace App\Http\Controllers;
use App\Botman\MainConversation;
use Illuminate\Http\Request;
use BotMan\BotMan\Middleware\ApiAi;
use BotMan\BotMan\Middleware\Dialogflow;
class BotManController extends Controller
{
public function handle()
{
$botman = app('botman');
$dialogflow = Dialogflow::create('en');
$botman->middleware->received($dialogflow);
$botman->hears('getzone', function ($bot) {
$extras = $bot->getMessage()->getExtras('apiParameters');
$apiReply = $extras['geo-city'];
$bot->reply('hi');
})->middleware($dialogflow);
$botman->listen();
}
}

how to prepare api using laravel and vue.js

good day;
I am new in vue.js and I want to build API in my project using vue.js and laravel
I have some question and answer because I got confused
I have services controller that return all service
as below:-
class ServicesController extends Controller
{
public function Services()
{
//get all serveice
$services=Services::where(['deleted'=>1,'status'=>1])->get();
return response()->json($services);
}
}
and API route as below:-
Route::get('/Servicess', 'API\ServicesController#Services');
it is necessary to make a component to send a request to using
Axios request to get data and if yes how to tell the mobile developer about a link to access it.
i want the steps from vue.js side to
prepare data and send it using Axios
You can not use your front-end javascript code inside php controllers, there are two ways to use the data; First: send it via the request. Second: fetch the required data at the back-end side and use it there.
Also there are many alternatives to Axios like the fetch api etc.
Update#1:
example controller
use Illuminate\Http\Request;
class ExampleController extends Controller
{
public function exampleMethod(Request $request){
$name = $request->input('name');
//DO sth
}
}
Route in api.php:
Route::get('/users', 'API\ExampleController#exampleMethod');

Laravel 5.6 testing Notification::assertSentTo() not found

Struggling since multiple days to get Notification::assertSentTo() method working in my feature test of reset password emails in a Laravel 5.6 app, yet receiving ongoing failures with following code:
namespace Tests\Feature;
use Tests\TestCase;
use Illuminate\Auth\Notifications\ResetPassword;
use Illuminate\Support\Facades\Notification;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Foundation\Testing\RefreshDatabase;
class UserPasswordResetTest extends TestCase
{
public function test_submit_password_reset_request()
{
$user = factory("App\User")->create();
$this->followingRedirects()
->from(route('password.request'))
->post(route('password.email'), [ "email" => $user->email ]);
Notification::assertSentTo($user, ResetPassword::class);
}
}
I have tried several ideas including to use Illuminate\Support\Testing\Fakes\NotificationFake directly in the use list.
In any attempt the tests keep failing with
Error: Call to undefined method Illuminate\Notifications\Channels\MailChannel::assertSentTo()
Looking forward to any hints helping towards a succesful test.
Regards & take care!
It seems like you are missing a Notification::fake(); For the correct fake notification driver to be used.
Notification::fake();
$this->followingRedirects()
...

How to replay message by irazasyed telegram freamwork in Laravel 5.0 setwebhook

I used Laravel 5.0 and Irazasyed telegram bot, I want work by webhook and when a person send message to telegram bot, the telegram send a message automatically to that.
My code is here bot not worked by webhook:
<?php namespace App\Http\Controllers;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Technical;
use Illuminate\Support\Facades\Session;
use Url;
use Telegram\Bot\Api;
use Telegram\Bot\Laravel\Facades\Telegram;
use Artisaninweb\SoapWrapper\Facades\SoapWrapper;
class HomeController extends Controller {
public function __construct()
{
//$this->middleware('auth');
}
public function index()
{
$telegram = new Api('117451573:*********************', 'true');
$telegram->setWebhook(['url' => 'https://******.com/117451573:********************/webhook']);
$update = $telegram->getWebhookUpdates();
$telegram->sendMessage([
'chat_id' => '********',
'text' => 'thanks',
]);
return response()->json(["status" => "success"]);
}
}
I am trying to get Irazasyed's Telegram Bot SDK to work as well. Heres a tutorial: Let's make a Telegram bot with PHP, that seems to be up to date. I had not the time to test it by myself. Will come hopefully the next days.
To use webhooks its seems you have to call the following command in the shell once.
curl -H "Content-Type: application/json" -X POST -d '{"url":"https://www.example.com/my-secret-webhook.php"}' https://api.telegram.org/botYOUR_BOT_TOKEN/setWebhook
see chapter II. Configuring the Webhook at the tutorial.
Good luck

Send email from queued event handler

I use Lumen 5.1 and Redis for queues. And I have a pretty standard event handler that should send an email:
<?php
namespace App\Handlers\Events;
use Illuminate\Contracts\Queue\ShouldQueue;
use App\Events\UserHasRegistered;
use Illuminate\Contracts\Mail\Mailer;
class SendWelcomeEmail implements ShouldQueue
{
protected $mailer;
public function __construct(Mailer $mailer)
{
$this->mailer = $mailer;
}
public function handle(UserHasRegistered $event)
{
$user = $event->user;
$this->mailer->raw('Test Mail', function ($m) use ($user) {
$name = $user->getFirstName().''.$user->getLastName();
$m->to($user->auth()->getEmail(), $name)->subject('This is a test.');
});
}
}
The email is sent when I don't use the ShouldQueue interface. But when I push the event handler to the queue (i. e. use the ShouldQueue interface), the email is not sent and I don't get any error messages.
Do you have any ideas how to solve or debug this?
It was not a bug, just an unexpected behaviour.
I am using Xampp on Windows and the php mail driver for development. For some reason the queued mails were not saved in the default mailoutput folder within the Xampp directory. Instead a new mailoutput folder was automatically created within the Lumen directory.
There I found all the missed mails. :)

Resources