2. Sending messages

Using console:

# Get the list of devices
$ python manage.py fcm_messenger --devices
> Devices list:
> (#1) My phone

# python manage.py fcm_messenger --device_id=<device_id> --msg=<message> [--collapse-key <key>]
$ python manage.py fcm_messenger --device_id=1 --msg='my test message'

Using Django orm:

from fcm.utils import get_device_model
Device = get_device_model()

my_phone = Device.objects.get(name='My phone')
my_phone.send_message({'message':'my test message'}, collapse_key='something')

collapse_key parameter is optional (default message).

If you want to send additional arguments like delay_while_idle or other, add them as named variables e.g.:

my_phone.send_message({'message':'my test message'}, delay_while_idle=True, time_to_live=5)

Note

For more information, see Lifetime of a Message and Sending a downstream message docs.

2.1. Multicast message

django-fcm supports sending messages to multiple devices at once. E.g.:

from fcm.utils import get_device_model
Device = get_device_model()

Device.objects.all().send_message({'message':'my test message'})

2.2. Topic messaging

django-fcm supports sending messages to multiple devices that have opted in to a particular fcm topic:

from fcm.api import FCMMessage

FCMMessage().send({'message':'my test message'}, to='/topics/my-topic')

Note

For more information, see Send messages to topics.