Laravel package for sending notifications with Threema.

v1.1.1 2024-01-13 22:00 UTC

This package is not auto-updated.

Last update: 2024-05-08 00:52:06 UTC


Laravel package for sending notifications with Threema.


  1. Add the following repository to your composer.json:
	"repositories": [
			"type": "package",
			"package": {
				"name": "threema/msgapi-sdk",
				"version": "1.5.6",
				"dist": {
					"url": "https://gateway.threema.ch/sdk/threema-msgapi-sdk-php-1.5.6.zip",
					"type": "zip"
  1. Install the package with Composer:
composer require ablota/laravel-threema-notification-channel
  1. Request a Threema Gateway ID. Register to get a basic ID for testing immediately. If you are interested in an end-to-end ID, contact Threema and they will usually provide you with an ID for testing.


The package includes a configuration file. However, you are not required to export this configuration file to your own application. You can simply use the environment variables below:

// Required

// Optional

The required variables are shown on the Threema Gateway website. The THREEMA_GATEWAY_PRIVATE_KEY is required in hex if you're using the end-to-end mode.

Formatting Notifications

If a notification supports being sent as a Threema message, you should define a toThreema method on the notification class. This method will receive a $notifiable entity and should return an Illuminate\Notifications\Messages\ThreemaMessage instance. Let's take a look at a basic toThreema example:

use Illuminate\Notifications\Messages\ThreemaMessage;
use Illuminate\Notifications\Messages\ThreemaTextMessage;

public function toThreema(mixed $notifiable): ThreemaMessage
	return new ThreemaTextMessage('Hello World!');

Right now only 1:1 chat messages (text, image, location, audio, video, file) are supported. Group message types are coming soon.

Routing Notifications

To route Threema notifications to the proper Threema ID, define a routeNotificationForThreema method on your notifiable entity:

use Threema\MsgApi\Receiver;

public function routeNotificationForThreema(mixed $notification): Receiver
	return new Receiver($this->threema_id, Receiver::TYPE_ID);

By using Receiver::TYPE_EMAIL or Receiver::TYPE_PHONE you can make use of an automatic ID lookup.


The package only throws the following exceptions:


Is thrown in case of fatal errors. For example, if certain types are not supported or the configuration is incorrect.


Since Laravel does not return a result when sending notifications, this exception is thrown instead. For example, sending a message to an unknown Threema ID would lead into this exception. It should be caught and the result it contains should be processed:

use Illuminate\Notifications\Exceptions\ThreemaChannelResultException;

try {
	$notifiable->notify(new TwoFactorVerificationCode());
} catch(ThreemaChannelResultException $exception) {