3 Someone's Mattermost API v4 bindings.
4 Copyright (c) 2016-2023 by Someone <someone@somenet.org> (aka. Jan Vales <jan@jvales.net>)
5 published under MIT-License
7 post stdin to a channel.
13 from inspect import cleandoc
23 if "MM_APIURL" in os.environ:
24 mm_api = mattermost.MMApi(os.environ["MM_APIURL"])
29 if ("MM_USER" in os.environ and "MM_PASS" in os.environ) or ("MM_BEARER" in os.environ):
30 if "MM_BEARER" in os.environ:
31 mm_api.login(bearer=os.environ["MM_BEARER"])
33 mm_api.login(os.environ["MM_USER"], os.environ["MM_PASS"])
38 if "MM_CHANID" in os.environ:
39 chan_id = os.environ["MM_CHANID"]
44 if len(sys.argv) < 1 or len(sys.argv) > 3:
49 print(cleandoc("""required ENV-parameters: MM_APIURL, MM_USER+MM_PASS or MM_BEARER, MM_CHANID.
50 arguments: [PREFIX] [SUFFIX]
57 prefix = sys.argv[1].replace("\\n", "\n")
58 suffix = sys.argv[2].replace("\\n", "\n")
62 print("Posting to channel:" +str(mm_api.create_post(chan_id, prefix+sys.stdin.read()+suffix, props={"from_webhook":"true"})))
67 if __name__ == '__main__':