@@ -29,16 +29,14 @@ async def on_message(self, msg: Message):
29
29
from_contact = msg .talker ()
30
30
text = msg .text ()
31
31
room = msg .room ()
32
+ if room :
33
+ await room .ready ()
34
+
32
35
# send contact-card
33
- print (msg )
34
36
if msg .type () == MessageType .MESSAGE_TYPE_CONTACT :
35
37
# we can receive the contact-card event, and get the contact from message
36
38
contact = await msg .to_contact ()
37
39
38
- # you can send all file to the specific room when you are at testing stage
39
- room = self .Room .load ('room-id' )
40
- await room .ready ()
41
-
42
40
if text == 'send card' :
43
41
# find one of my friend to send to `from_contact`
44
42
contacts = await bot .Contact .find_all ()
@@ -51,15 +49,18 @@ async def on_message(self, msg: Message):
51
49
img = await msg .to_file_box ()
52
50
# save the image as local file
53
51
await img .to_file (f'./{ img .name } ' )
54
- # send image file to the specific room
55
- await room .say (img )
52
+ # send image file to the room
53
+ if room :
54
+ await room .say (img )
56
55
57
56
elif msg .type () == MessageType .MESSAGE_TYPE_VIDEO :
58
57
video = await msg .to_file_box ()
59
58
# save the video as local file
60
59
await video .to_file (f'./{ video .name } ' )
61
- # send video file to the specific room
62
- await room .say (video )
60
+
61
+ # send video file to the room
62
+ if room :
63
+ await room .say (video )
63
64
64
65
elif msg .type () == MessageType .MESSAGE_TYPE_AUDIO :
65
66
audio = await msg .to_file_box ()
0 commit comments