/ src / invitation / __pycache__ / dispatcher.cpython-312.pyc
dispatcher.cpython-312.pyc
 1 2  U�i��	���ddlZddlZddlZddlZddlmZddlmZmZejjejjejjejje����Zejje�	ddlmZdZGd�d�Zd	Zejj)ed
 3  ddd
�ZGd�d�Zedk(r~eej2�dkred�ej6d�ej2dZeej2�dkDrej2dndZe�Zej?ee�yy#e$rdZY��wxYw)�N)�datetime)�Dict�Any)�	AgentMailTFc�4�eZdZd�ZGd�d�Ze�Zy)�
MockAgentMailc� �td|���y)Nz [MOCK] Initialized with config: )�print)�self�kwargss  �F/Volumes/sil/Brainiac/projects/ENVOY/xray/src/invitation/dispatcher.py�__init__zMockAgentMail.__init__s��
�0���9�:�c�.�eZdZGd�d�Ze�Zy)�MockAgentMail.Inboxesc��eZdZed��Zy)�MockAgentMail.Inboxes.Messagesc�b�td|jd��d|jd����y)Nz[MOCK EMAIL SENT] To: �toz, Subject: �subject)r
 4  �get)rs r
�sendz#MockAgentMail.Inboxes.Messages.sends-���.�v�z�z�$�/?�.@��F�J�J�W`�La�Kb�c�drN)�__name__�
 5  __module__�__qualname__�staticmethodr�rr
�Messagesrs��
�
e��
errN)rrrr�messagesrrr
�Inboxesrs��	e�	e�
 6  �:�rr N)rrrrr �inboxesrrr
rrs��;����i�Grrz./Users/cybe/.config/agentmail/credentials.json�exchange�threads�logszinvitations_sent.logc�z�eZdZefdefd�Zdeeeffd�Zdedeeeffd�Z	ddedeeeffd	�Z
 7  ddedefd
 8  �Zy)
�InvitationDispatcher�
 9  creds_pathc�l�||_|j�|_|jjd�|_|jjdd�|_tr/|jr#t|j��|_d|_	yt|j��|_d|_	y)N�api_key�inbox_idzfrancois@agentmail.to)r)FT)r'�_load_creds�credsrr)r*�
HAS_AGENTMAILr�client�is_mockr)rr's  r
rzInvitationDispatcher.__init__#s{��$����%�%�'��
10  ��z�z�~�~�i�0����
1112  ���z�3J�K��
��T�\�\�#�D�L�L�9�D�K� �D�L�'����=�D�K��D�Lr�returnc��tjj|j�rNt	d|j���	t|jd�5}t
j|�cddd�St	d|j���iS#1swYnxYw�'#t$r}t	d|���icYd}~Sd}~wwxYw)z'Loads credentials from the config path.u✓ Found credentials at �rNu✗ Error loading credentials: u✗ No credentials found at )	�os�path�existsr'r
13  �open�json�load�	Exception)r�f�es   r
r+z InvitationDispatcher._load_creds0s���
�7�7�>�>�$�/�/�*��-�d�o�o�->�?�@�
��$�/�/�3�/�1��9�9�Q�<�0�/�
14  	�,�T�_�_�,=�>�?��	�
0�/��/���
��7��s�;�<��	��
�s6�B�B�.	B�B�B�	C�(B=�7C�=C�email�payloadc��tj�j�dz||j�D��cic]\}}|dk7s�||��c}}dd�}t	j
15  tjjt�d��ttd�5}|jtj|�dz�d	d	d	�y	cc}}w#1swYy	xYw)
16  z/Logs the invitation to the persistent log file.�Z�
17  magic_link�sent)�	timestamp�	recipient�payload_summary�statusT)�exist_ok�a�
18  N)
r�utcnow�	isoformat�itemsr3�makedirsr4�dirname�INVITATION_LOG_PATHr6�writer7�dumps)rr<r=�k�v�	log_entryr:s       r
�_log_invitationz$InvitationDispatcher._log_invitation=s���"���*�4�4�6��<��18����V����A�A��DU��1���V��	
19  �	�	���B�G�G�O�O�$7�8�4�H�
�%�s�
+�q�
�G�G�D�J�J�y�)�D�0�1�,�
+�� W�,�
+�s�
C
20  �C
21  �(C�C�	user_namec�V�dttj�dz���}||ddd�S)z2Generates a mock cryptographic invitation payload.zhttps://envoy.ai/join?token=i�z
22  ENVOY Xrayz*A P2P collaborative multimedia experiment.)rUr@�
23  experiment�note)�int�time)rrUr@s   r
�create_invitation_payloadz.InvitationDispatcher.create_invitation_payloadLs7��4�C��	�	��d�8J�4K�3L�M�
24  �"�$�&�@�	
25  �	
26  rc	��|j|�}d|d��}d|d�d|d�d�}d|d�d	|d�d
27  |d�d|d�d�	}td
|�d��	|jjjj|j||||ddg��td�|j||�y#t$r}td|����d}~wwxYw)z)Sends the invitation email via AgentMail.zYou are invited to join rWz
28  Hello rUz�,
29  
30  You have been invited to join the ENVOY Xray experiment, a P2P collaborative multimedia project.
31  
32  To get started, follow your personal "Magic Link" below:
33  r@z3
34  
35  Welcome to the mesh.
36  
37  -- The ENVOY Swarm
38          z�
39          <html>
40              <body style="font-family: sans-serif; color: #333; line-height: 1.6;">
41                  <h1 style="color: #2c3e50;">Welcome to ENVOY</h1>
42                  <p>Hello <strong>zL</strong>,</p>
43                  <p>You have been invited to join the <strong>z�</strong> experiment, a P2P collaborative multimedia project.</p>
44                  <p style="margin: 20px 0;">
45                      <a href="a�" 
46                         style="background-color: #3498db; color: white; padding: 12px 24px; text-decoration: none; border-radius: 4px; display: inline-block;">
47                         Join the Experiment
48                      </a>
49                  </p>
50                  <p>If the button doesn't work, copy and paste this link into your browser:</p>
51                  <p style="color: #7f8c8d; font-size: 0.9em;">a</p>
52                  <hr style="border: 0; border-top: 1px solid #eee; margin: 30px 0;">
53                  <p style="font-size: 0.8em; color: #95a5a6;">Welcome to the mesh. This is an automated invitation from the ENVOY Swarm.</p>
54              </body>
55          </html>
56          u🚀 Dispatching invitation to z...zenvoy-invitation�onramp)r*rr�text�html�labelsu✅ Invitation sent!u❌ Error sending invitation: N)	r[r
57  r.r!rrr*rTr9)rr<rUr=r�	text_body�	html_bodyr;s        r
�send_invitationz$InvitationDispatcher.send_invitationWs:���0�0��;��,�W�\�-B�,C�D����{����
58  	����	�
�	�"�#*�+�"6�!7�8>�>E�l�>S�=T�U�%�l�3�4�5>�?F�l�>S�=T�U	��	�(	�/��w�c�:�;�
	��K�K���(�(�-�-��������*�H�5�

.�
�
�(�)�� � ���0���	��2�1�#�6�7���	�s�AB3�3	C�<C�CN)�Friend)rrr�DEFAULT_CREDS_PATH�strrrrr+rTr[rcrrr
r&r&"so��);� �3� ��T�#�s�(�^��
2�S�
2�4��S��>�
2�	
59  �3�	
60  �d�3�PS�8�n�	
61  �5�S�5�S�5rr&�__main__�z0Usage: python3 dispatcher.py <email> [user_name]�rd) r7r3�sysrZr�typingrrr4rM�abspath�__file__�
62  ENVOY_ROOT�append�	agentmailrr-�ImportErrorrre�joinrNr&r�len�argvr
63  �exit�email_to�name�
64  dispatcherrcrrr
�<module>rys:���	�
65  �����W�W�_�_�R�W�W�_�_�R�W�W�_�_�R�W�W�_�_�X�=V�-W�X�
Y�
66  ������
67  ���#��M�
68  
69  �
70  �F���g�g�l�l�:�z�9�f�Nd�e��j�j�X�z��
71  �3�8�8�}�q��
�@�A��������x�x��{�H��c�h�h�-�!�+�3�8�8�A�;��D�%�'�J����x��.������M��s�!E"�"E,�+E,