now responds too a message
This commit is contained in:
@@ -2,4 +2,7 @@
|
|||||||
HOMESERVER_URL = "https://matrix.org"
|
HOMESERVER_URL = "https://matrix.org"
|
||||||
USER_ID = "@botbot_user:matrix.org"
|
USER_ID = "@botbot_user:matrix.org"
|
||||||
PASSWORD = "botbot_password"
|
PASSWORD = "botbot_password"
|
||||||
LOG_LEVEL=INFO
|
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
|
# Set working directory
|
||||||
WORKDIR /app
|
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
|
# Install dependencies
|
||||||
COPY requirements.txt .
|
COPY requirements.txt .
|
||||||
RUN pip install --no-cache-dir -r requirements.txt
|
RUN pip install --no-cache-dir -r requirements.txt
|
||||||
|
|||||||
19
main.py
19
main.py
@@ -28,7 +28,8 @@ async def message_callback(room: MatrixRoom, event: RoomMessageText):
|
|||||||
logger.debug("Message callback triggered")
|
logger.debug("Message callback triggered")
|
||||||
if event.sender == USER_ID:
|
if event.sender == USER_ID:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
body = event.body.strip().lower()
|
||||||
logger.info("Message from %s in %s: %s", event.sender, room.display_name, event.body)
|
logger.info("Message from %s in %s: %s", event.sender, room.display_name, event.body)
|
||||||
|
|
||||||
if event.body.strip().lower() == "!ping":
|
if event.body.strip().lower() == "!ping":
|
||||||
@@ -38,13 +39,27 @@ async def message_callback(room: MatrixRoom, event: RoomMessageText):
|
|||||||
content={"msgtype": "m.text", "body": "Pong!"}
|
content={"msgtype": "m.text", "body": "Pong!"}
|
||||||
)
|
)
|
||||||
logger.info("Replied with Pong! to %s", event.sender)
|
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():
|
async def main():
|
||||||
global client
|
global client
|
||||||
logger.debug(HOMESERVER_URL)
|
logger.debug(HOMESERVER_URL)
|
||||||
logger.debug(USER_ID)
|
logger.debug(USER_ID)
|
||||||
# Configure client with persistent store
|
# Configure client with persistent store
|
||||||
config = AsyncClientConfig(store_sync_tokens=True)
|
config = AsyncClientConfig(
|
||||||
|
store_sync_tokens=True,
|
||||||
|
encryption_enabled=True,
|
||||||
|
)
|
||||||
client = AsyncClient(
|
client = AsyncClient(
|
||||||
HOMESERVER_URL,
|
HOMESERVER_URL,
|
||||||
USER_ID,
|
USER_ID,
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
matrix-nio[aio,http]>=0.25.0
|
matrix-nio[e2e]>=0.25.0
|
||||||
python-dotenv>=1.0.0
|
python-dotenv>=1.0.0
|
||||||
Reference in New Issue
Block a user