python-zulip-api/zulip/zulip/examples/send-message
Anders Kaseorg e30b3b094b Modernize legacy Python 2 syntax with pyupgrade.
Generated by `pyupgrade --py3-plus --keep-percent-format` followed by
manual indentation fixes.

Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-18 15:04:36 -07:00

30 lines
837 B
Python
Executable file

#!/usr/bin/env python3
import argparse
import zulip
usage = """send-message [options] <recipients>
Sends a test message to the specified recipients.
Example: send-message --type=stream commits --subject="my subject" --message="test message"
Example: send-message user1@example.com user2@example.com
"""
parser = zulip.add_default_arguments(argparse.ArgumentParser(usage=usage))
parser.add_argument('recipients', nargs='+')
parser.add_argument('--subject', default='test')
parser.add_argument('--message', default='test message')
parser.add_argument('--type', default='private')
options = parser.parse_args()
client = zulip.init_from_options(options)
message_data = {
'type': options.type,
'content': options.message,
'subject': options.subject,
'to': options.recipients,
}
print(client.send_message(message_data))