99
99
NewsletterMetadata ,
100
100
PrivacySettings ,
101
101
ProfilePictureInfo ,
102
+ SendRequestExtra ,
102
103
StatusPrivacy ,
103
104
UploadReturnFunction ,
104
105
GroupInfo ,
134
135
DocumentMessage ,
135
136
ContactMessage ,
136
137
)
138
+ from .proto .waConsumerApplication .WAConsumerApplication_pb2 import ConsumerApplication
139
+ from .proto .waMsgApplication .WAMsgApplication_pb2 import MessageApplication
137
140
from .types import MessageServerID , MessageWithContextInfo
138
141
from .utils import add_exif , gen_vcard , log , validate_link
139
142
from .utils .enum import (
@@ -2494,6 +2497,30 @@ def get_message_for_retry(
2494
2497
if not model .isEmpty :
2495
2498
return model .Message
2496
2499
2500
+ def send_fb_message (
2501
+ self ,
2502
+ to : JID ,
2503
+ message : ConsumerApplication ,
2504
+ metadata : MessageApplication .Metadata ,
2505
+ extra : SendRequestExtra ,
2506
+ ):
2507
+ to_buff = to .SerializeToString ()
2508
+ message_buff = message .SerializeToString ()
2509
+ metadata_buff = metadata .SerializeToString ()
2510
+ extra_buff = extra .SerializeToString ()
2511
+ response = self .__client .SendFBMessage (
2512
+ self .uuid ,
2513
+ to_buff ,
2514
+ len (to_buff ),
2515
+ message_buff ,
2516
+ len (message_buff ),
2517
+ metadata_buff ,
2518
+ len (metadata_buff ),
2519
+ extra_buff ,
2520
+ len (extra_buff ),
2521
+ )
2522
+ return SendResponse .FromString (response .get_bytes ())
2523
+
2497
2524
def connect (self ):
2498
2525
"""Establishes a connection to the WhatsApp servers."""
2499
2526
# Convert the list of functions to a bytearray
@@ -2538,9 +2565,8 @@ def disconnect(self) -> None:
2538
2565
self .__client .Disconnect (self .uuid )
2539
2566
2540
2567
2541
-
2542
2568
class ClientFactory :
2543
- def __init__ (self , database_name : str = ' neonize.db' ) -> None :
2569
+ def __init__ (self , database_name : str = " neonize.db" ) -> None :
2544
2570
"""
2545
2571
This class is used to create new instances of the client.
2546
2572
"""
@@ -2559,31 +2585,39 @@ def get_all_devices_from_db(db: str) -> List["Device"]:
2559
2585
c_string = gocode .GetAllDevices (db .encode ()).decode ()
2560
2586
if not c_string :
2561
2587
return []
2562
-
2588
+
2563
2589
class Device :
2564
- def __init__ (self , JID : JID , PushName : str , BussinessName : str = None , Initialized : bool = None ):
2590
+ def __init__ (
2591
+ self ,
2592
+ JID : JID ,
2593
+ PushName : str ,
2594
+ BussinessName : str = None ,
2595
+ Initialized : bool = None ,
2596
+ ):
2565
2597
self .JID = JID
2566
2598
self .PushName = PushName
2567
2599
self .BusinessName = BussinessName
2568
2600
self .Initialized = Initialized
2569
2601
2570
2602
devices : list [Device ] = []
2571
2603
2572
- for device_str in c_string .split (' |\u0001 |' ):
2573
- id , push_name , bussniess_name , initialized = device_str .split (',' )
2574
- id , server = id .split ('@' )
2604
+ for device_str in c_string .split (" |\u0001 |" ):
2605
+ id , push_name , bussniess_name , initialized = device_str .split ("," )
2606
+ id , server = id .split ("@" )
2575
2607
jid = build_jid (id , server )
2576
2608
2577
- device = Device (jid , push_name , bussniess_name , initialized == ' true' )
2609
+ device = Device (jid , push_name , bussniess_name , initialized == " true" )
2578
2610
devices .append (device )
2579
-
2611
+
2580
2612
return devices
2581
2613
2582
2614
def get_all_devices (self ) -> List ["Device" ]:
2583
2615
"""Retrieves all devices associated with the current account from the database."""
2584
2616
return self .get_all_devices_from_db (self .database_name )
2585
2617
2586
- def new_client (self , jid : JID = None , uuid : str = None , props : Optional [DeviceProps ] = None ) -> NewClient :
2618
+ def new_client (
2619
+ self , jid : JID = None , uuid : str = None , props : Optional [DeviceProps ] = None
2620
+ ) -> NewClient :
2587
2621
"""
2588
2622
This function creates a new instance of the client. If the jid parameter is not provided, a new client will be created.
2589
2623
:param name: The name of the client.
@@ -2601,7 +2635,7 @@ def new_client(self, jid: JID = None, uuid: str = None, props: Optional[DevicePr
2601
2635
raise Exception ("JID and UUID cannot be none" )
2602
2636
2603
2637
client = NewClient (self .database_name , jid , props , uuid )
2604
- self .clients .append (client )
2638
+ self .clients .append (client )
2605
2639
return client
2606
2640
2607
2641
def run (self ):
@@ -2612,4 +2646,4 @@ def run(self):
2612
2646
name = client .uuid ,
2613
2647
).start ()
2614
2648
2615
- Event .default_blocking (None )
2649
+ Event .default_blocking (None )
0 commit comments