Skip to content

Set Twitter username in TwitterDirectMessage from User model routeNotificationForTwitter #88

@sts-ryan-holton

Description

@sts-ryan-holton

I have a routeNotificationForTwitter on my User model which returns the Twitter username for my user, how can I access this within my notification's toTwitter method?

/**
 * Route the notification for Twitter.
 *
 * @return string
 */
public function routeNotificationForTwitter($notification)
{
    try {
        $availableIntegration = AvailableIntegration::where('slug', 'twitter')
                                                    ->first();

        $userIntegration = UserIntegration::where('user_id', $this->id)
                                          ->where('available_integration_id', $availableIntegration->id)
                                          ->first();

        if (!$userIntegration) {
            return null;
        }

        return $userIntegration->schema->twitter_username;
    } catch (\Exception $e) { }

    return null;
}
    /**
     * Get the Twitter representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function toTwitter($notifiable)
    {
        $data = [
            'type' => 'monitor-down',
            'name' => $this->emailData['monitor_name'],
            'url' => $this->emailData['monitor_url'],
            'value' => 'down'
        ];

        try {
            $this->createHistoryEntry('twitter', 'Monitor Down', $data, $notifiable);
        } catch (\Exception $e) { }

        $monitorName = $this->emailData['monitor_name'];
        $monitorURL = $this->emailData['monitor_url'];

        return new TwitterDirectMessage("factfinder_all", "Your monitor $monitorName -- ($monitorURL) -- has just gone DOWN");
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions