Skip to main content

API for rendering Chat App Card json.

Project description

Python Card Framework

This is a library designed to allow Python developers to treat the Chat API JSON to be generated for cards and dialogs as objects, each capable of rendering themselves into valid JSON instead of hand-crafting or cut-and-pasting JSON in large blocks.

The exact JSON that is being rendered can be found in the official Google Developer Docs pages here: https://developers.google.com/chat/api/reference/rest/v1/spaces.messages?hl=en

Intention

In order to generate or send messages from a chat application to the user, the messages must be formed of valid JSON objects. In the event that the message is malformed, a simple 'Chat App not responding' message is returned. This leads to the developer having to insert large blocks of JSON in their Python code, much of which is boiler-plate and can easily lead to hard to find cut and paste errors.

As a result this library of objects has been created to alleviate the problem. The developer can now create and manipulate first-class Python objects which know how to correctly render themselves. Thus, instead of inserting this:

  return {
    "sections": [
        {
          "widgets": [
            {
              "decoratedText": {
                "topLabel": "Hello, my name is Inigo Montoya",
                "text": "You killed my father. Prepare to die.",
                "startIcon": {
                  "knownIcon": "PERSON"
                }
              }
            }
        ]
      }
    ],
    "header": {
      "title": "The Princess Bride",
      "imageUrl": "https://source.unsplash.com/featured/320x180?nature&sig=8",
      "imageType": "CIRCLE"
    }
  }

... the developer can instead do this (with the appropriate imports, of course):

from card_framework.v2 import Card, CardHeader, Message, Section
from card_framework.v2.widgets import DecoratedText, Icon
text = DecoratedText(top_label='Hello, my name is Inigo Montoya',
                     text='You killed my father. Prepare to die.',
                     start_icon=Icon(known_icon=Icon.KnownIcon.PERSON))
widgets = [text]
header = CardHeader(title='The Princess Bride',
                    image_url='https://source.unsplash.com/featured320x180?nature&sig=8')
card = Card(header=header, sections=[Section(widgets=widgets)])

return Message(cards=[card]).render()

which will return the correct JSON.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

python_card_framework-2.4.0.tar.gz (30.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

python_card_framework-2.4.0-py3-none-any.whl (70.2 kB view details)

Uploaded Python 3

File details

Details for the file python_card_framework-2.4.0.tar.gz.

File metadata

  • Download URL: python_card_framework-2.4.0.tar.gz
  • Upload date:
  • Size: 30.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.11

File hashes

Hashes for python_card_framework-2.4.0.tar.gz
Algorithm Hash digest
SHA256 d8cd6bb8a7198d825ace4c0327473fd876dd364954184c985719463848f4c09e
MD5 d2b1055be3c195eb9ea23ee72cc9d37d
BLAKE2b-256 991690364ab2fc054fabc7004cea5e1fea3edd36f3a78a3578bceffd0626cc0e

See more details on using hashes here.

File details

Details for the file python_card_framework-2.4.0-py3-none-any.whl.

File metadata

File hashes

Hashes for python_card_framework-2.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4d848356814b46cdcfaf65872e9783bafb1ce26197020df2d8ac53612a03d8f6
MD5 7e1215265fd9685c7eb490d646581b19
BLAKE2b-256 cb146b7c79442aff9125bb43a7fccd86d3072986ae34c39145a0a44bd44cc084

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page