rveachkc / pymsteams

Format messages and post to Microsoft Teams.
https://pypi.org/project/pymsteams/
Apache License 2.0
426 stars 79 forks source link

printme() should return string rather than printing #42

Closed martinthurn closed 5 years ago

martinthurn commented 5 years ago

Or rather, I guess it would be nice to have a new method such as as_string() so that we can get a string and print it to where WE choose (e.g. log file).

rveachkc commented 5 years ago

Instead of adding another method, would you consider just referencing the payload class attribute? It's a python object, but can also be dumped to json or pretty printed.

Example:

# setup
teams_message = pymsteams.connectorcard(os.getenv("MS_TEAMS_WEBHOOK"))
teams_message.text("This is a simple text message.")
teams_message.title("Simple Message Title")

# dump to json string
import json
json.dumps(teams_message.payload)
# output: '{"text": "This is a simple text message.", "title": "Simple Message Title"}'

# pretty printing
import pprint
pprint.pprint(teams_message.payload)
# output: {'text': 'This is a simple text message.', 'title': 'Simple Message Title'}
martinthurn commented 5 years ago

This is good, thank you!