Git Product home page Git Product logo

Comments (4)

punyflash avatar punyflash commented on June 17, 2024

Hello. In fact, in most cases you would not want any exception thrown by laravel's notification, but I do agree that there is no detection except log if notification was failed. I'll try to rework this, but for now you may create a custom channel that will serve your needs and send notification using it.

from telebot.

FallenKnight85 avatar FallenKnight85 commented on June 17, 2024

maybe you could just fire an event like "MessageFailed" Event where users can listen to.
On the event pass some contexts [$e, $notifiable]; so users who'd like to handle a FailedMessage event can listen and handle the event via Listeners.

from telebot.

punyflash avatar punyflash commented on June 17, 2024

maybe you could just fire an event like "MessageFailed" Event where users can listen to. On the event pass some contexts [$e, $notifiable]; so users who'd like to handle a FailedMessage event can listen and handle the event via Listeners.

Yeah, that first I thought about too, but I'll take some time to see may be there some kind of way to deal with that in laravel already

from telebot.

punyflash avatar punyflash commented on June 17, 2024

Updated in 2.0.1 release. Now instead of writing exceptions to the log, channel will emit events on sending, success and failure. If needed in 1.x version, gladly will accept pull request.

/**
 * Send Telegram Notification.
 *
 * @param  mixed        $notifiable
 * @param  Notification $notification
 * @return mixed
 */
public function send($notifiable, Notification $notification)
{
    $data = call_user_func([$notification, 'toTelegram'], $notifiable);
    $data = new TelegramNotification((string) $data);
    $data = $data->jsonSerialize();
    $bot = $this->botmanager->bot($data['bot'] ?? null);

    $this->dispatcher->dispatch(new NotificationSending($notifiable, $notification, static::class));

    $promises = [];
    $errors = [];

    foreach (($data['actions'] ?? []) as $action) {
        $promises[] = $bot->async()->exceptions()
            ->{$action['method']}($action['arguments'])
            ->otherwise(function (Exception $exception) use (&$errors) {
                $errors[] = $exception;
                return $exception;
            });
    }

    $results = Utils::unwrap($promises);
    $report = count($errors) ?
        new NotificationFailed($notifiable, $notification, static::class, $results) :
        new NotificationSent($notifiable, $notification, static::class, $results);

    $this->dispatcher->dispatch($report);
    return $results;
}

from telebot.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.