Giter VIP home page Giter VIP logo

Comments (9)

MrWeb avatar MrWeb commented on June 5, 2024 1

Wow thank you @irazasyed for the fast response. I referred to that docs as they are linked inside "Available Methods" section.

Ok I'll have a look at the Laravel 10 version (https://laravel.com/docs/10.x/notifications#notification-events) and see what I can come up with. Tku very much.

from telegram.

irazasyed avatar irazasyed commented on June 5, 2024 1

Updated links!

from telegram.

irazasyed avatar irazasyed commented on June 5, 2024 1

No. You need to listen to the NotificationSent event.

// EventServiceProvider.php
use App\Listeners\LogTelegramNotification;
use Illuminate\Notifications\Events\NotificationSent;
 
/**
 * The event listener mappings for the application.
 *
 * @var array
 */
protected $listen = [
    NotificationSent::class => [
        LogTelegramNotification::class,
    ],
];
// LogTelegramNotification

/**
 * Handle the event.
 */
public function handle(NotificationSent $event): void
{
    // $event->channel
    // $event->notifiable
    // $event->notification
    // $event->response
}

There is no need for you to dispatch or do anything. Just listen to the standard notification sent event and you'll get complete data in your listener such as the channel, notifiable, the response from Telegram (or any other channel -- you should filter based on this available data).

from telegram.

irazasyed avatar irazasyed commented on June 5, 2024 1

That's not supported. You'll have to either use the Telegram Bot SDK for that or create a helper yourself. The core idea of this channel is to deliver one-way notifications.

The channel cannot be used to support full Telegram API methods as that's not the purpose of this package.

from telegram.

irazasyed avatar irazasyed commented on June 5, 2024

You should use notification events, more on this in the docs: handling response.

Also, those docs you've mentioned are not related to this package.

from telegram.

irazasyed avatar irazasyed commented on June 5, 2024

No problem :)

It's actually linked to refer supported parameters which can be used with the options method to pass any additional params.

Probably should just replace the link to official documentation. Thanks for highlighting.

from telegram.

MrWeb avatar MrWeb commented on June 5, 2024

I have trouble in implementing it.
So do I have to create a TelegramMessageSentEvent event, then add it to EventServiceProvider inside $listen array like this with a listener connected:

protected $listen = [
    //other methods
    TelegramMessageSentEvent::class => [
        TelegramNotificationStatus::class
    ]
];

Then inside Notifications\TelegramNotification add the event() helper:

public function toTelegram()
{
    $msg = TelegramMessage::create();

    if ($this->reply_to_message_id) {
        $msg = $msg->options(['reply_to_message_id' => $this->reply_to_message_id]);
    }

    event(new TelegramMessageSentEvent($msg));

    return $msg->content($this->text);
}

I'm lost what to do inside TelegramMessageSentEvent::class and TelegramNotificationStatus::class :(

from telegram.

irazasyed avatar irazasyed commented on June 5, 2024

There's also Notification Failed event which if you listen to that event will get some useful data to help you debug the issues or take appropriate action. https://github.com/laravel-notification-channels/telegram/blob/master/src/TelegramChannel.php#L59-L63

from telegram.

MrWeb avatar MrWeb commented on June 5, 2024

Amazing, I was able to log the message_id !

Now I noticed the API have the deleteMessage('message_id') method, but I don't see them in this package. Did I missed them?

I would like to delete a specific message after some seconds, so once is sent, inside LogTelegramNotification::class I can probably just do:

public function handle(NotificationSent $event): void
{
    //some logic
    sleep(60);
    deleteMessage($event->response['result']['message_id']);
}

from telegram.

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.