Skip to content

Commit 80d3d6c

Browse files
committed
update the message-file-box
1 parent 6027ac6 commit 80d3d6c

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

examples/advanced/message-file-bot.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,33 +32,40 @@ async def on_message(self, msg: Message):
3232
# send contact-card
3333
print(msg)
3434
if msg.type() == MessageType.MESSAGE_TYPE_CONTACT:
35+
# we can receive the contact-card event, and get the contact from message
3536
contact = await msg.to_contact()
36-
room = self.Room.load('19961884194@chatroom')
37+
38+
# you can send all file to the specific room when you are at testing stage
39+
room = self.Room.load('room-id')
3740
await room.ready()
3841

3942
if text == 'send card':
40-
# find one of my friend
43+
# find one of my friend to send to `from_contact`
4144
contacts = await bot.Contact.find_all()
4245
if contacts:
4346
# send one of my friend to the talker
47+
# !! this interface is not supported now
4448
await from_contact.say(contacts[0])
4549
print('have sended')
4650
elif msg.type() == MessageType.MESSAGE_TYPE_IMAGE:
4751
img = await msg.to_file_box()
52+
# save the image as local file
4853
await img.to_file(f'./{img.name}')
49-
54+
# send image file to the specific room
5055
await room.say(img)
5156

5257
elif msg.type() == MessageType.MESSAGE_TYPE_VIDEO:
5358
video = await msg.to_file_box()
59+
# save the video as local file
5460
await video.to_file(f'./{video.name}')
55-
61+
# send video file to the specific room
5662
await room.say(video)
5763

5864
elif msg.type() == MessageType.MESSAGE_TYPE_AUDIO:
5965
audio = await msg.to_file_box()
6066
# save the audio file as local file
6167
await audio.to_file(f'./{audio.name}')
68+
# !! we can't send audio to room/contact
6269

6370
print('done')
6471

0 commit comments

Comments
 (0)