smart_message 0.0.4 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +51 -0
- data/README.md +244 -9
- data/docs/architecture.md +2 -0
- data/docs/examples.md +2 -0
- data/docs/getting-started.md +11 -0
- data/docs/properties.md +213 -7
- data/examples/01_point_to_point_orders.rb +27 -11
- data/examples/02_publish_subscribe_events.rb +16 -7
- data/examples/03_many_to_many_chat.rb +56 -22
- data/examples/04_redis_smart_home_iot.rb +48 -21
- data/examples/05_proc_handlers.rb +12 -5
- data/examples/06_custom_logger_example.rb +34 -13
- data/examples/07_error_handling_scenarios.rb +477 -0
- data/examples/tmux_chat/bot_agent.rb +4 -1
- data/examples/tmux_chat/shared_chat_system.rb +50 -22
- data/lib/smart_message/base.rb +105 -8
- data/lib/smart_message/errors.rb +3 -0
- data/lib/smart_message/header.rb +32 -5
- data/lib/smart_message/property_descriptions.rb +5 -4
- data/lib/smart_message/property_validations.rb +141 -0
- data/lib/smart_message/version.rb +1 -1
- metadata +3 -1
@@ -13,12 +13,21 @@ puts
|
|
13
13
|
|
14
14
|
# Define the Order Message
|
15
15
|
class OrderMessage < SmartMessage::Base
|
16
|
-
|
17
|
-
|
18
|
-
property :
|
19
|
-
|
20
|
-
property :
|
21
|
-
|
16
|
+
description "Represents customer orders for processing through the payment system"
|
17
|
+
|
18
|
+
property :order_id,
|
19
|
+
description: "Unique identifier for the order (e.g., ORD-1001)"
|
20
|
+
property :customer_id,
|
21
|
+
description: "Unique identifier for the customer placing the order"
|
22
|
+
property :amount,
|
23
|
+
description: "Total order amount in decimal format (e.g., 99.99)"
|
24
|
+
property :currency,
|
25
|
+
default: 'USD',
|
26
|
+
description: "ISO currency code for the order (defaults to USD)"
|
27
|
+
property :payment_method,
|
28
|
+
description: "Payment method selected by customer (credit_card, debit_card, paypal, etc.)"
|
29
|
+
property :items,
|
30
|
+
description: "Array of item names or descriptions included in the order"
|
22
31
|
|
23
32
|
# Configure to use memory transport for this example
|
24
33
|
config do
|
@@ -35,11 +44,18 @@ end
|
|
35
44
|
|
36
45
|
# Define the Payment Response Message
|
37
46
|
class PaymentResponseMessage < SmartMessage::Base
|
38
|
-
|
39
|
-
|
40
|
-
property :
|
41
|
-
|
42
|
-
property :
|
47
|
+
description "Contains payment processing results sent back to the order system"
|
48
|
+
|
49
|
+
property :order_id,
|
50
|
+
description: "Reference to the original order being processed"
|
51
|
+
property :payment_id,
|
52
|
+
description: "Unique identifier for the payment transaction (e.g., PAY-5001)"
|
53
|
+
property :status,
|
54
|
+
description: "Payment processing status: 'success', 'failed', or 'pending'"
|
55
|
+
property :message,
|
56
|
+
description: "Human-readable description of the payment result"
|
57
|
+
property :processed_at,
|
58
|
+
description: "ISO8601 timestamp when the payment was processed"
|
43
59
|
|
44
60
|
config do
|
45
61
|
transport SmartMessage::Transport::StdoutTransport.new(loopback: true)
|
@@ -13,13 +13,22 @@ puts
|
|
13
13
|
|
14
14
|
# Define the User Event Message
|
15
15
|
class UserEventMessage < SmartMessage::Base
|
16
|
-
|
17
|
-
|
18
|
-
property :
|
19
|
-
|
20
|
-
property :
|
21
|
-
|
22
|
-
property :
|
16
|
+
description "Broadcasts user activity events to multiple notification services"
|
17
|
+
|
18
|
+
property :event_id,
|
19
|
+
description: "Unique identifier for this event (e.g., EVT-1001)"
|
20
|
+
property :event_type,
|
21
|
+
description: "Type of user event: 'user_registered', 'user_login', 'password_changed', etc."
|
22
|
+
property :user_id,
|
23
|
+
description: "Unique identifier for the user performing the action"
|
24
|
+
property :user_email,
|
25
|
+
description: "Email address of the user for notification purposes"
|
26
|
+
property :user_name,
|
27
|
+
description: "Display name of the user"
|
28
|
+
property :timestamp,
|
29
|
+
description: "ISO8601 timestamp when the event occurred"
|
30
|
+
property :metadata,
|
31
|
+
description: "Additional event-specific data (source, location, IP, etc.)"
|
23
32
|
|
24
33
|
config do
|
25
34
|
transport SmartMessage::Transport::StdoutTransport.new(loopback: true)
|
@@ -14,15 +14,26 @@ puts
|
|
14
14
|
|
15
15
|
# Define the Chat Message
|
16
16
|
class ChatMessage < SmartMessage::Base
|
17
|
-
|
18
|
-
|
19
|
-
property :
|
20
|
-
|
21
|
-
property :
|
22
|
-
|
23
|
-
property :
|
24
|
-
|
25
|
-
property :
|
17
|
+
description "Represents chat messages exchanged between users in chat rooms"
|
18
|
+
|
19
|
+
property :message_id,
|
20
|
+
description: "Unique identifier for this chat message"
|
21
|
+
property :room_id,
|
22
|
+
description: "Identifier of the chat room where message was sent"
|
23
|
+
property :sender_id,
|
24
|
+
description: "Unique identifier of the user or bot sending the message"
|
25
|
+
property :sender_name,
|
26
|
+
description: "Display name of the message sender"
|
27
|
+
property :content,
|
28
|
+
description: "The actual text content of the chat message"
|
29
|
+
property :message_type,
|
30
|
+
description: "Type of message: 'user', 'bot', or 'system'"
|
31
|
+
property :timestamp,
|
32
|
+
description: "ISO8601 timestamp when message was sent"
|
33
|
+
property :mentions,
|
34
|
+
description: "Array of user IDs mentioned in the message (@username)"
|
35
|
+
property :metadata,
|
36
|
+
description: "Additional message data (reactions, edit history, etc.)"
|
26
37
|
|
27
38
|
config do
|
28
39
|
transport SmartMessage::Transport::StdoutTransport.new(loopback: true)
|
@@ -37,12 +48,20 @@ end
|
|
37
48
|
|
38
49
|
# Define Bot Command Message
|
39
50
|
class BotCommandMessage < SmartMessage::Base
|
40
|
-
|
41
|
-
|
42
|
-
property :
|
43
|
-
|
44
|
-
property :
|
45
|
-
|
51
|
+
description "Represents commands sent to chat bots for processing"
|
52
|
+
|
53
|
+
property :command_id,
|
54
|
+
description: "Unique identifier for this bot command"
|
55
|
+
property :room_id,
|
56
|
+
description: "Chat room where the command was issued"
|
57
|
+
property :user_id,
|
58
|
+
description: "User who issued the bot command"
|
59
|
+
property :command,
|
60
|
+
description: "The bot command name (e.g., 'weather', 'help', 'joke')"
|
61
|
+
property :parameters,
|
62
|
+
description: "Array of parameters passed to the bot command"
|
63
|
+
property :timestamp,
|
64
|
+
description: "ISO8601 timestamp when command was issued"
|
46
65
|
|
47
66
|
config do
|
48
67
|
transport SmartMessage::Transport::StdoutTransport.new(loopback: true)
|
@@ -57,12 +76,20 @@ end
|
|
57
76
|
|
58
77
|
# Define System Notification Message
|
59
78
|
class SystemNotificationMessage < SmartMessage::Base
|
60
|
-
|
61
|
-
|
62
|
-
property :
|
63
|
-
|
64
|
-
property :
|
65
|
-
|
79
|
+
description "System-generated notifications about chat room events and status changes"
|
80
|
+
|
81
|
+
property :notification_id,
|
82
|
+
description: "Unique identifier for this system notification"
|
83
|
+
property :room_id,
|
84
|
+
description: "Chat room affected by this notification"
|
85
|
+
property :notification_type,
|
86
|
+
description: "Type of notification: 'user_joined', 'user_left', 'room_created', etc."
|
87
|
+
property :content,
|
88
|
+
description: "Human-readable description of the system event"
|
89
|
+
property :timestamp,
|
90
|
+
description: "ISO8601 timestamp when the system event occurred"
|
91
|
+
property :metadata,
|
92
|
+
description: "Additional system event data and context"
|
66
93
|
|
67
94
|
config do
|
68
95
|
transport SmartMessage::Transport::StdoutTransport.new(loopback: true)
|
@@ -329,7 +356,11 @@ class BotAgent
|
|
329
356
|
end
|
330
357
|
|
331
358
|
def process_chat_message(chat_data)
|
332
|
-
#
|
359
|
+
# Don't respond to other bots to avoid infinite loops
|
360
|
+
return if chat_data['message_type'] == 'bot'
|
361
|
+
return if chat_data['sender_id'] == @bot_id # Don't respond to our own messages
|
362
|
+
|
363
|
+
# Bot can respond to certain keywords or patterns from human users only
|
333
364
|
content = chat_data['content'].downcase
|
334
365
|
|
335
366
|
if content.include?('hello') || content.include?('hi')
|
@@ -598,6 +629,9 @@ class DistributedChatDemo
|
|
598
629
|
puts "• Dynamic subscription and unsubscription"
|
599
630
|
puts "• Event-driven responses and interactions"
|
600
631
|
puts "• Service discovery and capability advertisement"
|
632
|
+
|
633
|
+
puts "\n🛑 Shutting down demo..."
|
634
|
+
sleep(1) # Give any pending messages time to process
|
601
635
|
end
|
602
636
|
end
|
603
637
|
|
@@ -58,14 +58,24 @@ SHARED_TRANSPORT = create_transport
|
|
58
58
|
|
59
59
|
# Sensor Data Message - Published by IoT devices
|
60
60
|
class SensorDataMessage < SmartMessage::Base
|
61
|
-
|
62
|
-
|
63
|
-
property :
|
64
|
-
|
65
|
-
property :
|
66
|
-
|
67
|
-
property :
|
68
|
-
|
61
|
+
description "Real-time sensor data from smart home IoT devices"
|
62
|
+
|
63
|
+
property :device_id,
|
64
|
+
description: "Unique identifier for the IoT device (e.g., THERM-001)"
|
65
|
+
property :device_type,
|
66
|
+
description: "Type of device: 'thermostat', 'security_camera', 'door_lock', 'smoke_detector'"
|
67
|
+
property :location,
|
68
|
+
description: "Physical location of device: 'living_room', 'kitchen', 'bedroom', 'garage'"
|
69
|
+
property :sensor_type,
|
70
|
+
description: "Type of sensor reading: 'temperature', 'humidity', 'motion', 'status'"
|
71
|
+
property :value,
|
72
|
+
description: "Numeric or boolean sensor reading value"
|
73
|
+
property :unit,
|
74
|
+
description: "Unit of measurement: 'celsius', 'percent', 'boolean', 'lux'"
|
75
|
+
property :timestamp,
|
76
|
+
description: "ISO8601 timestamp when sensor reading was taken"
|
77
|
+
property :battery_level,
|
78
|
+
description: "Battery percentage for battery-powered devices (0-100)"
|
69
79
|
|
70
80
|
config do
|
71
81
|
transport SHARED_TRANSPORT
|
@@ -88,11 +98,18 @@ end
|
|
88
98
|
|
89
99
|
# Device Command Message - Sent to control IoT devices
|
90
100
|
class DeviceCommandMessage < SmartMessage::Base
|
91
|
-
|
92
|
-
|
93
|
-
property :
|
94
|
-
|
95
|
-
property :
|
101
|
+
description "Commands sent to control and configure smart home IoT devices"
|
102
|
+
|
103
|
+
property :device_id,
|
104
|
+
description: "Target device identifier to receive the command"
|
105
|
+
property :command,
|
106
|
+
description: "Command to execute: 'set_temperature', 'lock_door', 'start_recording', 'test_alarm'"
|
107
|
+
property :parameters,
|
108
|
+
description: "Hash of command-specific parameters and values"
|
109
|
+
property :requested_by,
|
110
|
+
description: "Identifier of user, system, or automation that requested this command"
|
111
|
+
property :timestamp,
|
112
|
+
description: "ISO8601 timestamp when command was issued"
|
96
113
|
|
97
114
|
config do
|
98
115
|
transport SHARED_TRANSPORT
|
@@ -107,14 +124,24 @@ end
|
|
107
124
|
|
108
125
|
# Alert Message - For critical notifications
|
109
126
|
class AlertMessage < SmartMessage::Base
|
110
|
-
|
111
|
-
|
112
|
-
property :
|
113
|
-
|
114
|
-
property :
|
115
|
-
|
116
|
-
property :
|
117
|
-
|
127
|
+
description "Critical alerts and notifications from smart home monitoring systems"
|
128
|
+
|
129
|
+
property :alert_id,
|
130
|
+
description: "Unique identifier for this alert event"
|
131
|
+
property :severity,
|
132
|
+
description: "Alert severity level: 'low', 'medium', 'high', 'critical'"
|
133
|
+
property :alert_type,
|
134
|
+
description: "Type of alert: 'security_breach', 'fire_detected', 'device_offline', 'battery_low'"
|
135
|
+
property :device_id,
|
136
|
+
description: "Device that triggered the alert (if applicable)"
|
137
|
+
property :location,
|
138
|
+
description: "Physical location where alert was triggered"
|
139
|
+
property :message,
|
140
|
+
description: "Human-readable description of the alert condition"
|
141
|
+
property :timestamp,
|
142
|
+
description: "ISO8601 timestamp when alert was generated"
|
143
|
+
property :requires_action,
|
144
|
+
description: "Boolean indicating if immediate human action is required"
|
118
145
|
|
119
146
|
config do
|
120
147
|
transport SHARED_TRANSPORT
|
@@ -14,11 +14,18 @@ puts
|
|
14
14
|
|
15
15
|
# Define a simple notification message
|
16
16
|
class NotificationMessage < SmartMessage::Base
|
17
|
-
|
18
|
-
|
19
|
-
property :
|
20
|
-
|
21
|
-
property :
|
17
|
+
description "System notifications processed by different types of handlers"
|
18
|
+
|
19
|
+
property :type,
|
20
|
+
description: "Notification type: 'info', 'warning', 'error'"
|
21
|
+
property :title,
|
22
|
+
description: "Short title or subject of the notification"
|
23
|
+
property :message,
|
24
|
+
description: "Detailed notification message content"
|
25
|
+
property :user_id,
|
26
|
+
description: "Target user ID for the notification (optional)"
|
27
|
+
property :timestamp,
|
28
|
+
description: "ISO8601 timestamp when notification was created"
|
22
29
|
|
23
30
|
config do
|
24
31
|
transport SmartMessage::Transport::StdoutTransport.new(loopback: true)
|
@@ -285,11 +285,18 @@ end
|
|
285
285
|
|
286
286
|
# Sample message class with comprehensive logging
|
287
287
|
class OrderProcessingMessage < SmartMessage::Base
|
288
|
-
|
289
|
-
|
290
|
-
property :
|
291
|
-
|
292
|
-
property :
|
288
|
+
description "Order processing messages with comprehensive multi-logger configuration"
|
289
|
+
|
290
|
+
property :order_id,
|
291
|
+
description: "Unique identifier for the customer order"
|
292
|
+
property :customer_id,
|
293
|
+
description: "Identifier of the customer placing the order"
|
294
|
+
property :amount,
|
295
|
+
description: "Total monetary amount of the order"
|
296
|
+
property :status,
|
297
|
+
description: "Current processing status of the order"
|
298
|
+
property :items,
|
299
|
+
description: "Array of items included in the order"
|
293
300
|
|
294
301
|
config do
|
295
302
|
transport SmartMessage::Transport::StdoutTransport.new(loopback: true)
|
@@ -350,10 +357,16 @@ end
|
|
350
357
|
|
351
358
|
# Notification message with different logger configuration
|
352
359
|
class NotificationMessage < SmartMessage::Base
|
353
|
-
|
354
|
-
|
355
|
-
property :
|
356
|
-
|
360
|
+
description "User notifications with file-based logging configuration"
|
361
|
+
|
362
|
+
property :recipient,
|
363
|
+
description: "Target recipient for the notification"
|
364
|
+
property :subject,
|
365
|
+
description: "Subject line or title of the notification"
|
366
|
+
property :body,
|
367
|
+
description: "Main content body of the notification"
|
368
|
+
property :priority,
|
369
|
+
description: "Priority level of the notification (low, normal, high, urgent)"
|
357
370
|
|
358
371
|
config do
|
359
372
|
transport SmartMessage::Transport::StdoutTransport.new(loopback: true)
|
@@ -384,8 +397,12 @@ end
|
|
384
397
|
# Example: Message class using standard Ruby logger
|
385
398
|
# This demonstrates how to use Ruby's standard Logger in production code
|
386
399
|
class StandardLoggerMessage < SmartMessage::Base
|
387
|
-
|
388
|
-
|
400
|
+
description "Demonstrates integration with standard Ruby Logger for production logging"
|
401
|
+
|
402
|
+
property :content,
|
403
|
+
description: "Main content of the message to be logged"
|
404
|
+
property :level,
|
405
|
+
description: "Logging level for the message (debug, info, warn, error)"
|
389
406
|
|
390
407
|
config do
|
391
408
|
transport SmartMessage::Transport::StdoutTransport.new(loopback: true)
|
@@ -417,8 +434,12 @@ end
|
|
417
434
|
|
418
435
|
# Example: Message using the built-in Default Logger
|
419
436
|
class DefaultLoggerMessage < SmartMessage::Base
|
420
|
-
|
421
|
-
|
437
|
+
description "Demonstrates SmartMessage's built-in default logger with auto-detection"
|
438
|
+
|
439
|
+
property :message,
|
440
|
+
description: "The message content to be logged using default logger"
|
441
|
+
property :level,
|
442
|
+
description: "Log level (debug, info, warn, error, fatal)"
|
422
443
|
|
423
444
|
config do
|
424
445
|
transport SmartMessage::Transport::StdoutTransport.new(loopback: true)
|