Skip to main content

Streamlit component that styles a chat bubble.

Project description

chat-message

Streamlit component that allows you to style chat messages into chat bubbles. Uses daisyUI.

Installation instructions

pip install chat-message

Usage instructions

import streamlit as st
from chat_message import chat_message

user = {
  "id": 1,
  "name": "user1",
  "socket": "",
  "admin": False,
}

# simulated database data
rows = [
  {
    'message_id': 1,
    'message_msg': 'This is a test.',
    'message_roomId': 1,
    'message_time': datetime.datetime(2024, 7, 10, 6, 55, 59),
    'author_id': 1,
    'author_name': 'user1',
    'author_email': 'user1@example.com',
    'author_socket': ''
  },
  {
    'message_id': 2,
    'message_msg': 'This is only a test.',
    'message_roomId': 1,
    'message_time': datetime.datetime(2024, 7, 10, 6, 55, 59),
    'author_id': 2,
    'author_name': 'user2',
    'author_email': 'user2@example.com',
    'author_socket': ''
  }
]

result = []
for row in rows:
  obj = {
    "id": row["message_id"],
    "message": row["message_msg"],
    "room": row["message_roomId"],
    "time": row["message_time"].isoformat(),
    "author": {
      "id": row["author_id"],
      "name": row["author_name"],
      "socket": row["author_socket"]
    }
  }
  result.append(obj)

i = 0
for row in result:
  prev = None
  next = None

  if len(result) > 1:
    prev = result[i-1]

  if len(result) > i+1:
    next = result[i+1]

  appendTime = True
  appendUser = True

  if prev:
    if prev["author"]["id"] == row["author"]["id"]:
      diff = timeDiffInSecs(row["time"], prev["time"])
      if diff < 60:
        appendUser = False

  if next:
    if next["author"]["id"] == row["author"]["id"]:
      diff = timeDiffInSecs(next["time"], row["time"])
      if diff < 60:
        appendTime = False

  click = st_chat_message(row, user, appendUser, appendTime)
  print(click)

  i = i+1

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

chat-message-1.0.0.tar.gz (423.8 kB view details)

Uploaded Source

Built Distribution

chat_message-1.0.0-py3-none-any.whl (428.6 kB view details)

Uploaded Python 3

File details

Details for the file chat-message-1.0.0.tar.gz.

File metadata

  • Download URL: chat-message-1.0.0.tar.gz
  • Upload date:
  • Size: 423.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.2

File hashes

Hashes for chat-message-1.0.0.tar.gz
Algorithm Hash digest
SHA256 33a2c0c3420980a384e71309b4d83333a2027a4c46d2724c2abd70699af56295
MD5 89f51548b6ff58c90ea6464ce5aad48d
BLAKE2b-256 2fd2532079ad798c7e57ec4bdb1ec0d54ff0140c3036e2e68f1be1286d21281d

See more details on using hashes here.

File details

Details for the file chat_message-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: chat_message-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 428.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.2

File hashes

Hashes for chat_message-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8c7380a1f5731369515e8d598547a3641bdfdffa813d760d2bf51245891543ba
MD5 c2d257031d4203cf91c463c624a8609d
BLAKE2b-256 ac24e908c123739cdce7889574019e88c6dffd58b958f7b2d4b634e1845f4b73

See more details on using hashes here.

Supported by

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