深圳网站建设网站推广的方法,朝西村网站建设公司,医药网站建设,台州网站设计开发当前飞书webhook机器人还不支持发送文件类型的群消息#xff0c;可以申请创建一个机器人应用来实现群发送文件消息。  创建机器人后#xff0c;需要开通一系列权限#xff0c;然后发布。由管理员审核通过后#xff0c;才可使用。 
包括如下的权限#xff0c;可以获取群的c…当前飞书webhook机器人还不支持发送文件类型的群消息可以申请创建一个机器人应用来实现群发送文件消息。  创建机器人后需要开通一系列权限然后发布。由管理员审核通过后才可使用。 
包括如下的权限可以获取群的chat_id。  
开通权限发布应用后可以取到两个重要的参数 app_id app_secret 使用两个参数可以生成密钥tenant_access_token headers  {‘Authorization’: f’Bearer {get_token()}, ## 获取tenant_access_token, 需要替换为实际的token def get_token():# 获取tenant_access_token供上传图片接口使用url  https://open.feishu.cn/open-apis/auth/v3/tenant_access_token/internalheaders  {Content-Type: application/json; charsetutf-8,}payload_data  {app_id: cli_xxx,app_secret: xxx,}response  requests.post(urlurl, datajson.dumps(payload_data), headersheaders).json()print(response)token  response[tenant_access_token]return token 
上传文件 
def upload_file(file_path):try:file_name  file_path.split(,)[0]url  https://open.feishu.cn/open-apis/im/v1/filesform  {file_type: stream,file_name: file_name,file: (file_name, open(file_path, rb),text/plain)}  # 需要替换具体的path  具体的格式参考  https://www.w3school.com.cn/media/media_mimeref.aspmulti_form  MultipartEncoder(form)headers  {Authorization: fBearer {get_token()},  ## 获取tenant_access_token, 需要替换为实际的token}headers[Content-Type]  multi_form.content_typer  requests.request(POST, url, headersheaders, datamulti_form)print(r.json())# print(response.headers[X-Tt-Logid])  # for debug or oncall# print(response.content)  # Print Responseif r.json().get(code)  0 and r.json().get(msg)  success:logger.info(f上传文件到飞书成功msg{r.json()},{file_path})media_id  r.json().get(data).get(file_key)return media_idelse:logger.warning(f上传文件到飞书异常,{r.json()},{file_path})# Press the green button in the gutter to run the script.except Exception as e:# logger.warning(上传文件到企业微信失败)print(上传文件到飞书失败)print(e)# logger.warning(e)pass发送文件到群 
def send_file(file_pathNone, media_id):机器人应用上传文件if not media_id:media_id  upload_file(file_pathfile_path)time.sleep(1)url  https://open.feishu.cn/open-apis/im/v1/messages?receive_id_typechat_idmsgContent  {file_key: media_id}form  {content: json.dumps(msgContent),msg_type: file,receive_id: oc_xxx}headers  {Authorization: Bearer   get_token()}response  requests.post(urlurl, datajson.dumps(form), headersheaders)print(response.json())获取群的chat_id 
def get_qun_list():url  https://open.feishu.cn/open-apis/im/v1/chatsheaders  {Authorization: Bearer   get_token()}response  requests.get(urlurl, headersheaders)print(response.json())return response.json()[data][items]def get_ _by_name(qun_name):items  get_qun_list()for i in items:if i.get(name)  str(qun_name):print(i.get(chat_id))return i.get(chat_id)发送成功