A clean, type-safe interface for generating rich chat responses to the Google Chat API using the CardsV2 schema.
Project description
GChat Card Builder (v2)
Gchat Card Builder is a Python library that assists in the creation and management of chat "cards" for Google Chat responses via API. Supports CardsV2 format.
Table of Contents
Description
Gchat Card Builder provides an easy-to-use interface for creating richly formatted cards compatible with Google Chat. The goal is to stop mucking around with deeply nested structures just to send a slightly rich chat message.
Here's an example of how this could help clean up code:
# broken onto several lines for readability
gchat_response = copy.deepcopy(BIG_OLD_DICT_TEMPLATE)
widgets = gchat_response["cardsV2"][0]["card"]["sections"][0]["widgets"]
button = widgets[0]["buttonList"]["buttons"][0]
button["text"] = "click to get rick rolled"
button["onClick"]["openLink"]["url"] = "https://www.youtube.com/watch?v=dQw4w9WgXcQ"
becomes this:
builder = CardBuilder.create()
builder.add_section(
W.ButtonList(
buttons=[
W.Button(
text="click to get rick rolled",
onClick=W.OnClick(
openLink=W.OpenLink(
url='https://www.youtube.com/watch?v=dQw4w9WgXcQ',
)
)
)
]
),
)
gchat_response = builder.build()
Installation
Prerequisites
- Python (versions tested: 3.10, 3.11)
- may support others
Installation Steps
pip install gchatcardbuilder
Usage
Google Chat Card Builder provides an easy-to-use interface for creating richly formatted cards compatible with Google Chat. Here's how you can quickly start building cards using the factory method:
Basic Example:
from gchatcardbuilder import CardBuilder, CardWidgets as W
# Get builder instance using the factory method
builder = CardBuilder.create()
# Add card details
builder.set_card_id("sample_id")
builder.set_header(W.CardHeader(title="Test Header"))
builder.add_section(W.Section(header="Test Section", widgets=[]))
# Build the card
card = builder.build()
Documentation
You're looking at it.
Tests
If you're planning on contributing or wish to run tests to ensure the library functions as expected in your environment:
- Clone the repository:
git clone https://github.com/pkarl/gchatcardbuilder
- Navigate to the cloned directory and install the requirements:
pip install -r requirements.txt
- Run the tests:
pytest
If you have any questions, issues, or feedback, feel free to open an issue in the repository. Contributions are always welcome!
Maintained by PK2
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
Built Distribution
File details
Details for the file gchatcardbuilder-0.1.7.tar.gz
.
File metadata
- Download URL: gchatcardbuilder-0.1.7.tar.gz
- Upload date:
- Size: 13.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a44115f9481914c00df87f3f22f62289081d768f49b5dce3b9b1a4cf110b63ac |
|
MD5 | 6cdd5870690bd8b9843bf49dafaff1b7 |
|
BLAKE2b-256 | 89f7918540fc24ede5dc5b121c458573fa6a6d40c480493ac817b1ec121553f0 |
File details
Details for the file gchatcardbuilder-0.1.7-py3-none-any.whl
.
File metadata
- Download URL: gchatcardbuilder-0.1.7-py3-none-any.whl
- Upload date:
- Size: 14.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9dbebed1c344401a1efee45753a3cfeecfe96cea61cb0e95c870c6ec0ad0f1f9 |
|
MD5 | 9f1ce4fbf077f2d0f91cc6e9ff3fcb06 |
|
BLAKE2b-256 | dab358e058c7e5d22ce04dd42b46165c47354f03bd732e0945275b186f3137dd |