Exemple #1
0
def add_message(sender_id: int, message_text: str, chat_id: int, session: Optional[Session] = None) -> int:
    if session is None:
        session = create_session()
    message = Message()
    message.sender_id = sender_id
    message.dispatch_date = datetime.datetime.now()
    message.text = message_text
    message.chat_id = chat_id
    session.add(message)
    session.commit()
    return message.id
Exemple #2
0
def write_first_chat_message(chat_id: int, user_id: int, session: Optional[Session] = None) -> Message:
    if session is None:
        session = create_session()
    message = Message()
    message.sender_id = user_id
    message.dispatch_date = datetime.datetime.now()
    message.text = FIRST_CHAT_MESSAGE_TEXT
    message.chat_id = chat_id
    session.add(message)
    session.commit()
    session.query(Chat).filter(Chat.id == chat_id).update({"last_message_id": message.id})
    session.commit()
    return message