|
3 | 3 | import asyncio
|
4 | 4 | import logging
|
5 | 5 | from typing import Optional, Union
|
| 6 | +import json |
| 7 | +from dataclasses import asdict |
6 | 8 |
|
7 | 9 | from wechaty_puppet import FileBox, ScanStatus # type: ignore
|
8 | 10 | from wechaty_puppet import MessageType
|
@@ -34,33 +36,16 @@ async def on_message(self, msg: Message):
|
34 | 36 |
|
35 | 37 | if msg.type() == MessageType.MESSAGE_TYPE_MINI_PROGRAM:
|
36 | 38 | mini_program = await msg.to_mini_program()
|
37 |
| - await room.say(mini_program) |
38 | 39 |
|
39 |
| - if text == 'send card': |
40 |
| - # find one of my friend |
41 |
| - contacts = await bot.Contact.find_all() |
42 |
| - if contacts: |
43 |
| - # send one of my friend to the talker |
44 |
| - await from_contact.say(contacts[0]) |
45 |
| - print('have sended') |
46 |
| - elif msg.type() == MessageType.MESSAGE_TYPE_IMAGE: |
47 |
| - img = await msg.to_file_box() |
48 |
| - await img.to_file(f'./{img.name}') |
| 40 | + # save the mini-program data as string |
| 41 | + mini_program_data = asdict(mini_program.payload) |
49 | 42 |
|
50 |
| - await room.say(img) |
| 43 | + # load the min-program |
| 44 | + loaded_mini_program = self.MiniProgram.create_from_json( |
| 45 | + payload_data=mini_program_data |
| 46 | + ) |
51 | 47 |
|
52 |
| - elif msg.type() == MessageType.MESSAGE_TYPE_VIDEO: |
53 |
| - video = await msg.to_file_box() |
54 |
| - await video.to_file(f'./{video.name}') |
55 |
| - |
56 |
| - await room.say(video) |
57 |
| - |
58 |
| - elif msg.type() == MessageType.MESSAGE_TYPE_AUDIO: |
59 |
| - audio = await msg.to_file_box() |
60 |
| - # save the audio file as local file |
61 |
| - await audio.to_file(f'./{audio.name}') |
62 |
| - |
63 |
| - print('done') |
| 48 | + await room.say(loaded_mini_program) |
64 | 49 |
|
65 | 50 | async def on_login(self, contact: Contact):
|
66 | 51 | """login event. It will be triggered every time you login"""
|
|
0 commit comments