# -*- coding: UTF-8 -*- from larksuiteoapi.event import handle_event from larksuiteoapi.service.contact.v3 import UserUpdatedEventHandler, UserUpdatedEvent from larksuiteoapi.model import OapiHeader, OapiRequest from flask import Flask, request from flask.helpers import make_response from larksuiteoapi import Config, Context, DOMAIN_FEISHU, DefaultLogger, LEVEL_DEBUG # for Cutome APP(企业自建应用) app_settings = Config.new_internal_app_settings_from_env() # for memory store and logger(level=debug) conf = Config(DOMAIN_FEISHU, app_settings, log_level=LEVEL_DEBUG) def user_update_handle(ctx, conf, event): # type: (Context, Config, UserUpdatedEvent) ->None print(ctx.get_request_id()) print(event.header) print(event.event) pass # set event type 'contact.user.updated_v3' handle UserUpdatedEventHandler.set_callback(conf, user_update_handle) app = Flask(__name__)
# -*- coding: UTF-8 -*- from larksuiteoapi.service.contact.v3 import Service as ContactService, model from larksuiteoapi import DOMAIN_FEISHU, Config, LEVEL_DEBUG, LEVEL_INFO, \ LEVEL_WARN, LEVEL_ERROR # 企业自建应用的配置 # AppID、AppSecret: "开发者后台" -> "凭证与基础信息" -> 应用凭证(App ID、App Secret) # VerificationToken、EncryptKey:"开发者后台" -> "事件订阅" -> 事件订阅(Verification Token、Encrypt Key),非必需,订阅事件、消息卡片时必需 # 更多介绍请看:Github -> README.zh.md -> 如何构建应用配置(AppSettings) app_settings = Config.new_internal_app_settings( app_id='AppID', app_secret='AppSecret', verification_token='VerificationToken', encrypt_key='EncryptKey') # 当前访问的是飞书,使用默认内存存储、默认日志(Error 级别) # 更多介绍请看:Github -> README.zh.md -> 如何构建整体配置(Config) conf = Config(DOMAIN_FEISHU, app_settings, log_level=LEVEL_ERROR) service = ContactService(conf) if __name__ == '__main__': # body params body = model.User() body.name = '' body.mobile = '' department_ids_1 = [] body.department_ids = department_ids_1 body.employee_type = 0 req_call = service.users.create(body=body)
# -*- coding: UTF-8 -*- from larksuiteoapi.service.calendar.v4.api import Service as CalendarV4Service from sample.config.config import test_config_with_memory_store, test_config_with_redis_store from larksuiteoapi import DOMAIN_FEISHU, DOMAIN_LARK_SUITE, Config # for Cutome APP(企业自建应用) app_settings = Config.new_internal_app_settings_from_env() # for redis store and logger(level=debug) conf = test_config_with_redis_store(DOMAIN_FEISHU, app_settings) # for memory store and logger(level=debug) # conf = Config(DOMAIN_FEISHU, app_settings, log_level=LEVEL_DEBUG) def test_calendar_acls_delete(): service = CalendarV4Service(conf) resp = service.calendar_acls.delete().set_calendar_id( "calendar_id").set_acl_id("aclId").do() print('request id = %s' % resp.get_request_id()) print(resp.code) if resp.code == 0: print(resp.data.user) else: print(resp.msg) print(resp.error) if __name__ == '__main__': test_calendar_acls_delete()
# -*- coding: UTF-8 -*- from larksuiteoapi.api import Request, FormData, FormDataFile, set_timeout, set_path_params, set_query_params, \ set_is_response_stream, set_response_stream, set_tenant_key, set_need_help_desk_auth from larksuiteoapi import Config, ACCESS_TOKEN_TYPE_TENANT, ACCESS_TOKEN_TYPE_USER, ACCESS_TOKEN_TYPE_APP, \ APP_TICKET_KEY_PREFIX, DOMAIN_FEISHU, LEVEL_ERROR, LEVEL_DEBUG # for Cutome APP(企业自建应用) app_settings = Config.new_internal_app_settings(app_id='cli_a04677****8d01b', app_secret='XcplX2QLU7X******VJKHd6Yzvt', verification_token='', encrypt_key='', help_desk_id='696874*****390932', help_desk_token='ht-c82db92*******f5cf6e569aa') # for redis store and logger(level=debug) # conf = test_config_with_redis_store(DOMAIN_FEISHU, app_settings) # for memory store and logger(level=debug) conf = Config("https://open.feishu-boe.cn", app_settings, log_level=LEVEL_DEBUG) def test_ticket_detail(): req = Request('/open-apis/helpdesk/v1/tickets/6971250929135779860', 'GET', ACCESS_TOKEN_TYPE_TENANT, None, request_opts=[set_timeout(3), set_need_help_desk_auth()]) resp = req.do(conf) print('header = %s' % resp.get_header().items()) print('request id = %s' % resp.get_request_id()) print(resp.code) if resp.code == 0: print(resp.data)