utils package#

Submodules#

buttons module#

pynani.utils.buttons.basic_buttons(buttons: str | List[str | int]) List#

Creates a list of basic buttons.

Parameters:

buttons (Union[str, List[Union[str, int]]]) – The buttons to be created. It can be a string or a list of strings or integers.

Returns:

A list of dictionaries representing the basic buttons with their properties.

Return type:

List

Example

>>> basic_buttons(["Hello", "World", "πŸ”₯"])
[{'type': 'postback', 'title': 'Hello', 'payload': 'DEVELOPER_DEFINED_PAYLOAD', 'url': ''},
{'type': 'postback', 'title': 'World', 'payload': 'DEVELOPER_DEFINED_PAYLOAD', 'url': ''},
{'type': 'postback', 'title': 'πŸ”₯', 'payload': 'DEVELOPER_DEFINED_PAYLOAD', 'url': ''}]
>>> basic_buttons("Hello")
[{'type': 'postback', 'title': 'Hello', 'payload': 'DEVELOPER_DEFINED_PAYLOAD', 'url': ''}]
pynani.utils.buttons.exit_buttons(buttons: Dict | List[Dict]) List#

Creates a list of leave buttons.

Parameters:

buttons (Union[Dict, List[Dict]]) – The buttons to be created. It can be a dictionary or a list of dictionaries.

Returns:

A list of dictionaries representing the leave buttons with their properties.

Return type:

List

Example

>>> leave_buttons([{"title": "Hello", "url": "https://www.google.com"}, {"title": "World", "call_number": "+525555555555"}])
[{'type': 'web_url', 'title': 'Hello', 'payload': '', 'url': 'https://www.google.com'},
{'type': 'phone_number', 'title': 'World', 'payload': '+525555555555', 'url': ''}]
>>> leave_buttons({"title": "Hello", "url": "https://www.google.com"})
[{'type': 'web_url', 'title': 'Hello', 'payload': '', 'url': 'https://www.google.com'}]

quick_reply module#

pynani.utils.quick_reply.quick_buttons(buttons: List[str | int]) List[Dict]#

Prepares a list of quick reply buttons from a list of strings.

Parameters:

buttons (List[Union[str, int]]) – A list of strings or integers representing the text for each quick reply button.

Returns:

A list of dictionaries representing the quick reply buttons with their properties.

Return type:

List

Example

>>> quick_buttons(["Hello", "World"])
[{'content_type': 'text', 'title': 'Hello', 'payload': '<POSTBACK_PAYLOAD>', 'image_url': None},
{'content_type': 'text', 'title': 'World', 'payload': '<POSTBACK_PAYLOAD>', 'image_url': None}]
>>> quick_buttons([1, 2, 3])
[{'content_type': 'text', 'title': '1', 'payload': '<POSTBACK_PAYLOAD>', 'image_url': None},
{'content_type': 'text', 'title': '2', 'payload': '<POSTBACK_PAYLOAD>', 'image_url': None},
{'content_type': 'text', 'title': '3', 'payload': '<POSTBACK_PAYLOAD>', 'image_url': None}]
pynani.utils.quick_reply.quick_image_buttons(buttons: List[str | int], images: List[str]) List[Dict]#

Prepares a list of quick reply buttons from a list of strings.

Parameters:
  • buttons (List[str]) – A list of strings or integers representing the text for each quick reply button.

  • images (List[str]) – A list of strings representing the image URL for each quick reply button.

Returns:

A list of dictionaries representing the quick reply buttons with their properties.

Return type:

List

Example

>>> quick_image_buttons(["Hello", "World"], ["https://photos.com/hello.jpg", "https://photos.com/world.jpg"])
[{'content_type': 'text', 'title': 'Hello', 'payload': '<POSTBACK_PAYLOAD>', 'image_url': 'https://photos.com/hello.jpg'},
{'content_type': 'text', 'title': 'World', 'payload': '<POSTBACK_PAYLOAD>', 'image_url': 'https://photos.com/world.jpg'}]
If a button does not have an image, the image URL should be None or an empty string.
>>> quick_image_buttons(["Hello", "World", "Yes"], ["https://photos.com/hello.jpg", "https://photos.com/world.jpg", None])

receipt module#

pynani.utils.receipt.get_address(street_1: str, city: str, postal_code: str, state: str, country: str, street_2: str | None = None) Dict#

Constructs an address dictionary from the provided parameters.

Parameters:
  • street_1 (str) – The first line of the street address.

  • city (str) – The city of the address.

  • postal_code (str) – The postal code of the address.

  • state (str) – The state or province of the address.

  • country (str) – The country of the address.

  • street_2 (Optional[str], optional) – The second line of the street address. Defaults to None.

Returns:

A dictionary representing the address with its components.

Return type:

Dict

Example

>>> get_address("123 Main St", "Springfield", "12345", "IL", "US", "Apt 1")
{'street_1': '123 Main St', 'street_2': "Apt 1", 'city': 'Springfield', 'postal_code': '12345', 'state': 'IL', 'country': 'US'}
Optional parameters can be omitted:
>>> get_address("123 Main St", "Springfield", "12345", "IL", "US")
{'street_1': '123 Main St', 'street_2': None, 'city': 'Springfield', 'postal_code': '12345', 'state': 'IL', 'country': 'US'}
pynani.utils.receipt.get_adjustments(*args: str | int | float) List[Dict]#

Constructs a list of adjustments from the provided arguments.

Parameters:

*args (Union[str, int, float]) – A variable number of arguments, where each pair represents an adjustment name and amount.

Returns:

A list of dictionaries, each representing an adjustment with its name and amount.

Return type:

List[Dict]

Example

>>> get_adjustments("Discount", 10, "Tax", 20, "Shipping", 30)
[{'name': 'Discount', 'amount': 10}, {'name': 'Tax', 'amount': 20}, {'name': 'Shipping', 'amount': 30}]
pynani.utils.receipt.get_elements(title: str, price: float, subtitle: str | None = None, quantity: int | None = None, currency: str | None = 'USD', image_url: str | None = None) List[Dict]#

Constructs a list of elements from the provided parameters.

Parameters:
  • title (str) – The title of the item.

  • price (float) – The price of the item.

  • subtitle (Optional[str], optional) – The subtitle of the item. Defaults to None.

  • quantity (Optional[int], optional) – The quantity of the item. Defaults to None.

  • currency (Optional[str], optional) – The currency of the item. Defaults to β€˜USD’.

  • image_url (Optional[str], optional) – The URL of the item’s image. Defaults to None.

Returns:

A list of dictionaries representing the elements with their titles, prices, subtitles, quantities, currencies, and image URLs.

Return type:

List

Example

>>> get_elements("T-Shirt", 20.0, "Blue", 2, "USD", "https://example.com/tshirt.jpg")
[{'title': 'T-Shirt', 'subtitle': 'Blue', 'quantity': 2, 'price': 20.0, 'currency': 'USD', 'image_url': 'https://example.com/tshirt.jpg'}]
Optional parameters can be omitted:
>>> get_elements("T-Shirt", 20.0)
[{'title': 'T-Shirt', 'subtitle': None, 'quantity': None, 'price': 20.0, 'currency': 'USD', 'image_url': None}]
pynani.utils.receipt.get_summary(total_cost: float, subtotal: float | None = None, shipping_cost: float | None = None, total_tax: float | None = None) Dict#

Constructs a summary dictionary from the provided parameters.

Parameters:
  • total_cost (float) – The total cost of the order.

  • subtotal (Optional[float], optional) – The subtotal of the order. Defaults to None.

  • shipping_cost (Optional[float], optional) – The shipping cost of the order. Defaults to None.

  • total_tax (Optional[float], optional) – The total tax of the order. Defaults to None.

Returns:

A dictionary representing the summary with its components.

Return type:

Dict

Example

>>> get_summary(100.0, 90.0, 5.0, 5.0)
{'subtotal': 90.0, 'shipping_cost': 5.0, 'total_tax': 5.0, 'total_cost': 100.0}
Optional parameters can be omitted:
>>> get_summary(100.0)
{'subtotal': None, 'shipping_cost': None, 'total_tax': None, 'total_cost': 100.0}