
    Vhl                         d dl mZmZmZ eZdZdZdZ	 d dl	m
Z
mZ dZd dlmZ d d	lmZ d
 Zd Zd Zd Zedk(  r e        yy# e$ r dZY /w xY w)    )absolute_importdivisionprint_functiona  
module: bearychat
short_description: Send BearyChat notifications
description:
  - The M(community.general.bearychat) module sends notifications to U(https://bearychat.com) using the Incoming Robot integration.
author: "Jiangge Zhang (@tonyseek)"
extends_documentation_fragment:
  - community.general.attributes
attributes:
  check_mode:
    support: none
  diff_mode:
    support: none
options:
  url:
    type: str
    description:
      - BearyChat WebHook URL. This authenticates you to the bearychat service. It looks like
        V(https://hook.bearychat.com/=ae2CF/incoming/e61bd5c57b164e04b11ac02e66f47f60).
    required: true
  text:
    type: str
    description:
      - Message to send.
  markdown:
    description:
      - If V(true), text will be parsed as markdown.
    default: true
    type: bool
  channel:
    type: str
    description:
      - Channel to send the message to. If absent, the message goes to the default channel selected by the O(url).
  attachments:
    type: list
    elements: dict
    description:
      - Define a list of attachments. For more information, see
        U(https://github.com/bearyinnovative/bearychat-tutorial/blob/master/robots/incoming.md#attachments).
a  
- name: Send notification message via BearyChat
  local_action:
    module: bearychat
    url: |
      https://hook.bearychat.com/=ae2CF/incoming/e61bd5c57b164e04b11ac02e66f47f60
    text: "{{ inventory_hostname }} completed"

- name: Send notification message via BearyChat all options
  local_action:
    module: bearychat
    url: |
      https://hook.bearychat.com/=ae2CF/incoming/e61bd5c57b164e04b11ac02e66f47f60
    text: "{{ inventory_hostname }} completed"
    markdown: false
    channel: "#ansible"
    attachments:
      - title: "Ansible on {{ inventory_hostname }}"
        text: "May the Force be with you."
        color: "#ffffff"
        images:
          - http://example.com/index.png
zV
msg:
  description: Execution result.
  returned: success
  type: str
  sample: "OK"
)urlparse
urlunparseTF)AnsibleModule)	fetch_urlc                      i }|||d<   |||d<   |||d<   |*|j                  dg       j                   fd|D               d j                  |      z  }|S )Ntextmarkdownchannelattachmentsc           
   3      K   | ]O  }t        |j                  d       |j                  d      |j                  d      |j                  d             Q yw)titler   colorimagesN)&build_payload_for_bearychat_attachmentget).0itemmodules     o/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/general/plugins/modules/bearychat.py	<genexpr>z.build_payload_for_bearychat.<locals>.<genexpr>e   sP      5%  3)488F+;TXXg=N"$5%s   AAz
payload=%s)
setdefaultextendjsonify)r   r   r   r   r   payloads   `     r   build_payload_for_bearychatr   \   s    G&
$	="-44 5% $	5% 	%
 V^^G44GN    c                 ^   i }|||d<   |||d<   |||d<   ||j                  dg       }t        |t        t        f      s|g}|D ]c  }t        |t              rd|v rd|d   i}n4t        |d      r|j                  d      rd|i}n| j                  d	       |j                  |       e |S )
Nr   r   r   r   url
startswithhttpz@BearyChat doesn't have support for this kind of attachment imagemsg)	r   
isinstancelisttupledicthasattrr"   	fail_jsonappend)r   r   r   r   r   
attachmenttarget_imagesimages           r   r   r   n   s    J#
7!
6#
7"--h;&4-0XF 		(E%&5E>e--%2B2B62J  + ! ,   '		( r   c           	          t        | ||      \  }}|d   dk7  rOt        |      }t        |j                  |j                  ddddf      }| j                  d|d|d|d	   
       y y )N)datastatus   z
[obscured] z failed to send z to z: r%   r$   )r	   r   r   schemenetlocr+   )r   r!   r   responseinfourl_infoobscured_incoming_webhooks          r   do_notify_bearychatr;      sx    vs9NHdH~C=$.__hoo|RRH%J!2DKA 	 	B	 r   c            
         t        t        ddd      t        d      t        dd      t        d      t        dd	      d
      } t        s| j                  d       | j                  d   }| j                  d   }| j                  d   }| j                  d   }| j                  d   }t        | ||||      }t        | ||       | j                  d       y )NstrT)typerequiredno_log)r>   bool)defaultr>   r'   r)   )r>   elements)r!   r   r   r   r   )argument_speczurlparse is not installedr$   r!   r   r   r   r   OK)r   r)   HAS_URLPARSEr+   paramsr   r;   	exit_json)r   r!   r   r   r   r   r   s          r   mainrI      s    d;% F3U#&9* F 89
--
C== D}}Z(HmmI&G--.K)h6GW-
r   __main__N)
__future__r   r   r   r>   __metaclass__DOCUMENTATIONEXAMPLESRETURN+ansible.module_utils.six.moves.urllib.parser   r   rF   	Exceptionansible.module_utils.basicr   ansible.module_utils.urlsr	   r   r   r;   rI   __name__ r   r   <module>rV      s~    A @'R0
PL 5 /$2B2 zF k  Ls   
A AA