|
5 | 5 | # you can add your own custom bot functionalities via OpenAI's API function calls with this.
|
6 | 6 |
|
7 | 7 | import logging
|
| 8 | +import configparser |
| 9 | +from config_paths import CONFIG_PATH |
8 | 10 |
|
9 | 11 | # from api_get_openrouteservice import get_route, get_directions_from_addresses
|
10 | 12 | # from elasticsearch_handler import search_es # Import the Elasticsearch search function
|
11 | 13 |
|
| 14 | +# load and use logger |
| 15 | +logger = logging.getLogger(__name__) |
| 16 | +logger.setLevel(logging.INFO) |
| 17 | + |
| 18 | +# Read the config for enabled/disabled function calls |
| 19 | +config = configparser.ConfigParser() |
| 20 | +config.read(CONFIG_PATH) |
| 21 | +try: # Use try-except for safety |
| 22 | + enable_reminders = config.getboolean('Reminders', 'EnableReminders', fallback=False) |
| 23 | +except (configparser.NoSectionError, configparser.NoOptionError): |
| 24 | + enable_reminders = False |
| 25 | + |
| 26 | +# silently observe the chat |
12 | 27 | async def observe_chat():
|
13 | 28 | # Log observation or perform any silent monitoring if needed
|
14 | 29 | logging.info("Bot is currently observing the chat.")
|
@@ -149,6 +164,150 @@ async def observe_chat():
|
149 | 164 | }
|
150 | 165 | })
|
151 | 166 |
|
| 167 | +# ~~~~~~~~~~~~~~~~~~~~~~ |
| 168 | +# reminders (if enabled) |
| 169 | +# ~~~~~~~~~~~~~~~~~~~~~~ |
| 170 | + |
| 171 | +if enable_reminders: |
| 172 | + manage_reminder_function = { |
| 173 | + 'name': 'manage_reminder', |
| 174 | + 'description': """Manages user reminders (alerts); use if the user requests alerts, a timed notification, etc (hälytys, muistutus, ajastettu viesti..) Specify the action: 'add' to create, 'view' to list pending, 'delete' to remove by ID, or 'edit' to modify by ID. |
| 175 | + If you're unsure of the user's time zone, ask it first, and set the UTC alert accordingly. For instance, Finland is UTC+2 in winter and UTC+3 during summertime. Add the reminder in the user's own language! Suomeksi, jos käyttäjä puhuu suomea! Always ask the user's timezone if unsure. |
| 176 | +- For 'add': requires 'reminder_text' and exact 'due_time_utc' (ISO 8601 format, e.g., '2025-04-04T10:00:00Z'). Calculate UTC from user input based on current system UTC time. Notifications can be up to around 4000 characters or more. |
| 177 | +- For 'view': no other parameters needed. |
| 178 | +- For 'delete': requires 'reminder_id'. |
| 179 | +- For 'edit': requires 'reminder_id' and at least one of 'reminder_text' or 'due_time_utc'.""", |
| 180 | + 'parameters': { |
| 181 | + 'type': 'object', |
| 182 | + 'properties': { |
| 183 | + 'action': { |
| 184 | + 'type': 'string', |
| 185 | + 'enum': ['add', 'view', 'delete', 'edit'], |
| 186 | + 'description': "The operation: 'add', 'view', 'delete', or 'edit'." |
| 187 | + }, |
| 188 | + 'reminder_text': { |
| 189 | + 'type': 'string', |
| 190 | + 'description': "Text of the reminder, in the user's requested language. You can be a bit creative, like: 'Hey! You asked me to remind you... etc, emojis and basic Telegram HTML formatting is allowed.'. Required for 'add', optional for 'edit'." |
| 191 | + }, |
| 192 | + 'due_time_utc': { |
| 193 | + 'type': 'string', |
| 194 | + 'description': "Due time in UTC ISO 8601 format (YYYY-MM-DDTHH:MM:SSZ). Required for 'add', optional for 'edit'." |
| 195 | + }, |
| 196 | + 'reminder_id': { |
| 197 | + 'type': 'integer', |
| 198 | + 'description': "ID of the reminder. Required for 'delete' and 'edit'." |
| 199 | + } |
| 200 | + }, |
| 201 | + 'required': ['action'] |
| 202 | + } |
| 203 | + } |
| 204 | + custom_functions.append(manage_reminder_function) # Directly append if enabled |
| 205 | + logger.info("Reminder function 'manage_reminder' appended to custom_functions list.") |
| 206 | +else: |
| 207 | + logger.info("Reminders disabled in config.ini => 'manage_reminder' function not added.") |
| 208 | + |
| 209 | +# # original reminder method (tryout) |
| 210 | +# if enable_reminders: |
| 211 | +# # 1) Add a reminder |
| 212 | +# custom_functions.append({ |
| 213 | +# 'name': 'add_reminder', |
| 214 | +# 'description': ( |
| 215 | +# "[Use if the user wants to set a reminder for a future time.] " |
| 216 | +# "Accept user text and a date/time in UTC (YYYY-MM-DDTHH:MM:SSZ). " |
| 217 | +# "If user says 'in 5 minutes', parse that to a UTC time. " |
| 218 | +# "Return success/failure, and the ID of the reminder if successful." |
| 219 | +# ), |
| 220 | +# 'parameters': { |
| 221 | +# 'type': 'object', |
| 222 | +# 'properties': { |
| 223 | +# 'due_time_utc': { |
| 224 | +# 'type': 'string', |
| 225 | +# 'description': ( |
| 226 | +# "The date/time in UTC, e.g. 2025-01-02T13:00:00Z. " |
| 227 | +# "If user says something like 'in 5 minutes', parse into UTC. " |
| 228 | +# "If date/time is missing, ask user for clarification." |
| 229 | +# ) |
| 230 | +# }, |
| 231 | +# 'reminder_text': { |
| 232 | +# 'type': 'string', |
| 233 | +# 'description': ( |
| 234 | +# "What does the user want to be reminded of? E.g. 'Take out the trash'." |
| 235 | +# ) |
| 236 | +# } |
| 237 | +# }, |
| 238 | +# 'required': ['due_time_utc', 'reminder_text'] |
| 239 | +# } |
| 240 | +# }) |
| 241 | + |
| 242 | +# # 2) View all pending reminders |
| 243 | +# custom_functions.append({ |
| 244 | +# 'name': 'view_reminders', |
| 245 | +# 'description': ( |
| 246 | +# "[Use if the user wants to see their current/pending reminders.] " |
| 247 | +# "No arguments needed." |
| 248 | +# ), |
| 249 | +# 'parameters': { |
| 250 | +# 'type': 'object', |
| 251 | +# 'properties': {}, |
| 252 | +# 'required': [] |
| 253 | +# } |
| 254 | +# }) |
| 255 | + |
| 256 | +# # 3) Delete a reminder |
| 257 | +# custom_functions.append({ |
| 258 | +# 'name': 'delete_reminder', |
| 259 | +# 'description': ( |
| 260 | +# "[Use if the user wants to delete/cancel an existing reminder by ID.] " |
| 261 | +# "Reminders are typically identified by an integer ID." |
| 262 | +# ), |
| 263 | +# 'parameters': { |
| 264 | +# 'type': 'object', |
| 265 | +# 'properties': { |
| 266 | +# 'reminder_id': { |
| 267 | +# 'type': 'integer', |
| 268 | +# 'description': ( |
| 269 | +# "The ID number of the reminder to delete. " |
| 270 | +# "If user doesn't know the ID, prompt them to /viewreminders first or if they ask for you to show them their reminders." |
| 271 | +# ) |
| 272 | +# } |
| 273 | +# }, |
| 274 | +# 'required': ['reminder_id'] |
| 275 | +# } |
| 276 | +# }) |
| 277 | + |
| 278 | +# # 4) Edit a reminder (optional) |
| 279 | +# custom_functions.append({ |
| 280 | +# 'name': 'edit_reminder', |
| 281 | +# 'description': ( |
| 282 | +# "[Use if user wants to update an existing reminder. Provide the ID plus new text/time.] " |
| 283 | +# "Either 'due_time_utc' or 'reminder_text' or both can be changed." |
| 284 | +# ), |
| 285 | +# 'parameters': { |
| 286 | +# 'type': 'object', |
| 287 | +# 'properties': { |
| 288 | +# 'reminder_id': { |
| 289 | +# 'type': 'integer', |
| 290 | +# 'description': "The ID of the reminder to edit." |
| 291 | +# }, |
| 292 | +# 'due_time_utc': { |
| 293 | +# 'type': 'string', |
| 294 | +# 'description': ( |
| 295 | +# "The new date/time in UTC, e.g. 2025-01-02T13:00:00Z. " |
| 296 | +# "If user says 'tomorrow 10am', parse that into a UTC string." |
| 297 | +# ) |
| 298 | +# }, |
| 299 | +# 'reminder_text': { |
| 300 | +# 'type': 'string', |
| 301 | +# 'description': "The updated reminder text." |
| 302 | +# } |
| 303 | +# }, |
| 304 | +# 'required': ['reminder_id'] |
| 305 | +# } |
| 306 | +# }) |
| 307 | + |
| 308 | +# else: |
| 309 | +# logging.info("Reminders are disabled in config.ini => not adding reminder functions.") |
| 310 | + |
152 | 311 | # # jul 26 / 2024
|
153 | 312 | # custom_functions.append({
|
154 | 313 | # 'name': 'get_rss_feed',
|
|
0 commit comments