now responds too a message
This commit is contained in:
@@ -3,3 +3,6 @@ HOMESERVER_URL = "https://matrix.org"
|
||||
USER_ID = "@botbot_user:matrix.org"
|
||||
PASSWORD = "botbot_password"
|
||||
LOG_LEVEL=INFO
|
||||
|
||||
# comma-separated list of rooms or aliases to join on startup
|
||||
BOT_ROOMS=!room1:matrix.org,!another-room:matrix.org,!someroomalias:matrix.org
|
||||
@@ -3,6 +3,12 @@ FROM python:3.11-slim
|
||||
# Set working directory
|
||||
WORKDIR /app
|
||||
|
||||
# Install system dependencies
|
||||
RUN apt-get update && \
|
||||
apt-get install -y --no-install-recommends \
|
||||
libolm-dev build-essential python3-dev && \
|
||||
rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Install dependencies
|
||||
COPY requirements.txt .
|
||||
RUN pip install --no-cache-dir -r requirements.txt
|
||||
|
||||
17
main.py
17
main.py
@@ -29,6 +29,7 @@ async def message_callback(room: MatrixRoom, event: RoomMessageText):
|
||||
if event.sender == USER_ID:
|
||||
return
|
||||
|
||||
body = event.body.strip().lower()
|
||||
logger.info("Message from %s in %s: %s", event.sender, room.display_name, event.body)
|
||||
|
||||
if event.body.strip().lower() == "!ping":
|
||||
@@ -38,13 +39,27 @@ async def message_callback(room: MatrixRoom, event: RoomMessageText):
|
||||
content={"msgtype": "m.text", "body": "Pong!"}
|
||||
)
|
||||
logger.info("Replied with Pong! to %s", event.sender)
|
||||
elif body== "hello botbot":
|
||||
await client.room_send(
|
||||
room_id=room.room_id,
|
||||
message_type="m.room.message",
|
||||
content={
|
||||
"msgtype": "m.text",
|
||||
"body": "Hello! How can I assist you today?",
|
||||
},
|
||||
ignore_unverified_devices=True
|
||||
)
|
||||
logger.info("Replied with greeting to %s", event.sender)
|
||||
|
||||
async def main():
|
||||
global client
|
||||
logger.debug(HOMESERVER_URL)
|
||||
logger.debug(USER_ID)
|
||||
# Configure client with persistent store
|
||||
config = AsyncClientConfig(store_sync_tokens=True)
|
||||
config = AsyncClientConfig(
|
||||
store_sync_tokens=True,
|
||||
encryption_enabled=True,
|
||||
)
|
||||
client = AsyncClient(
|
||||
HOMESERVER_URL,
|
||||
USER_ID,
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
matrix-nio[aio,http]>=0.25.0
|
||||
matrix-nio[e2e]>=0.25.0
|
||||
python-dotenv>=1.0.0
|
||||
Reference in New Issue
Block a user