Skip to content

Instantly share code, notes, and snippets.

@astrotars
Created September 2, 2020 19:19
Show Gist options
  • Save astrotars/92559dda18f5808806fd054097d8d9b4 to your computer and use it in GitHub Desktop.
Save astrotars/92559dda18f5808806fd054097d8d9b4 to your computer and use it in GitHub Desktop.
from django.core.management.base import BaseCommand, CommandError
from django.conf import settings
from stream_chat import StreamChat
class Command(BaseCommand):
help = 'Broadcast the message on your channel'
def add_arguments(self, parser):
parser.add_argument('--message')
def handle(self, *args, **options):
client = StreamChat(api_key=settings.STREAM_API_KEY, api_secret=settings.STREAM_API_SECRET)
client.update_user({"id": "system", "name": "The Server"})
channel = client.channel("messaging", "kung-fu")
channel.create("system")
response = channel.send_message({"text": "AMA about kung-fu"}, 'system')
self.stdout.write(self.style.SUCCESS('Successfully posted a message with id "%s"' % response['message']['id']))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment