Skip to content

Latest commit

 

History

History
3950 lines (1799 loc) · 95.6 KB

api_reference.md

File metadata and controls

3950 lines (1799 loc) · 95.6 KB

Table of Contents

module adapter

Copyright 2022 SeaTalk Open Platform

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.


class BaseAdapter

method __init__

__init__(bot: 'CSBot', config: Dict[str, Any])

method extract_event

extract_event(
    raw_body: bytes,
    headers: Dict[str, str]
) → Optional[CallbackMessage]

method get_response

get_response(raw_body: bytes, headers: Dict[str, str]) → Any

method reply

reply(event: EventChatMessage, message: Message, quote_reply: bool = False)

method send

send(receiver_email: str, message: Message)

method send_group

send_group(
    group_name: str,
    message: Message,
    mentioned_emails: Optional[List[str]] = None
)

module adapters

module adapters.shopee_imbot

Copyright 2022 SeaTalk Open Platform

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.


class ReceiveNewMessageRequest

OnMessage callback request definition, used to deserialize the callback requests from the shopee_imbot callback server


class Adapter

Adapter implement to adapt the shopee_imbot callback server

method __init__

__init__(bot: 'CSBot', config: Dict[str, Any])

method encoded_content

encoded_content(message: Message)

method extract_event

extract_event(
    raw_body: bytes,
    headers: Dict[str, str]
) → Optional[CallbackMessage]

shopee-imbot has only one EventType: EventType.NEW_CHAT_MESSAGE :param raw_body: :param headers: :return:


method get_response

get_response(raw_body: bytes, headers: Dict[str, str]) → Any

method reply

reply(event: EventChatMessage, message: Message, quote_reply: bool = False)

method send

send(receiver_email: str, message: Message)

method send_group

send_group(
    group_name: str,
    message: Message,
    mentioned_emails: Optional[List[str]] = None
)

module adapters.sop_bot

Copyright 2022 SeaTalk Open Platform

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.


class Adapter

method __init__

__init__(bot: 'CSBot', config: Dict[str, Any])

Initialize the SOP Bot Adapter :param bot: CSBot instance :param config: StartupConfig.adapter


method extract_event

extract_event(
    raw_body: bytes,
    headers: Dict[str, str]
) → Optional[CallbackMessage]

https://open.seatalk.io/docs/messaging_messaging-events extract event from the callback request of the Seatalk Open Platform. :param raw_body: http body :param headers: http headers :rtype: protocol.CallbackMessage


method get_response

get_response(raw_body: bytes, headers: Dict[str, str]) → Any

:return: HTTP Response to return


method get_user_info

get_user_info(employee_codes: List[str]) → Dict[str, UserInfo]

get UserInfo by the employee_code :param employee_codes: employee_code of the Seatalk Open Platform :return: the respective user info


method reply

reply(event: CallbackMessage, message: Message, quote_reply: bool = False)

Let the bot reply a message :param quote_reply: whether to quote the incoming message, not supported yet :param event: the origin event to reply :param message: the reply :return: None :raise: raise ValueError on invalid input message


method send

send(receiver_email: str, message: Message)

let the bot send a message :param receiver_email: email :param message: Message Instance :return: None :raise: raise ValueError on invalid input message


method send_group

send_group(
    group_name: str,
    message: Message,
    mentioned_emails: Optional[List[str]] = None
)

module adapters.sop_bot.events

Copyright 2022 SeaTalk Open Platform

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.


class EventType

EventType definition of the Event Callback from Seatalk Open Platform. See details in https://open.seatalk.io/docs/messaging_messaging-events .


class Text

TextMessage definition. See details in https://open.seatalk.io/docs/messaging_messaging-events .


class ChatMessage

Message definition. See details in https://open.seatalk.io/docs/messaging_messaging-events .


class EventSingleChat

Event Definition of the Callback Event <message_from_bot_subscriber>. See details in https://open.seatalk.io/docs/messaging_messaging-events .


class EventNewSubscriber

Event Definition of the Callback Event <new_bot_subscriber>. See details in https://open.seatalk.io/docs/messaging_messaging-events .


class EventURLVerification

Event Definition of the Callback Event <event_verification>. See details in https://open.seatalk.io/docs/messaging_messaging-events .


class CallbackRequestBase

Common Fields of the Event Callback Request. See details in https://open.seatalk.io/docs/messaging_messaging-events .


class CallbackRequest

Event Callback Request definition See details in https://open.seatalk.io/docs/messaging_messaging-events .

module api_common

Copyright 2022 SeaTalk Open Platform

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Global Variables

  • API_AUTH_KEY

function standard_response

standard_response(
    code: int = 0,
    error: Any = '',
    data: Any = None,
    status: int = 200
) → Response

function plugin_not_found

plugin_not_found(plugin_name: str) → Response

function plugin_not_enabled

plugin_not_enabled(plugin_name: str) → Response

function plugin_config_invalid

plugin_config_invalid(errors: Optional[List])

function plugin_api_not_found

plugin_api_not_found(plugin_name: str, api_path: str, method: str) → Response

function plugin_api_auth_required

plugin_api_auth_required(
    plugin_name: str,
    api_path: str,
    method: str
) → Response

function plugin_api_no_permission

plugin_api_no_permission(
    plugin_name: str,
    api_path: str,
    method: str,
    role_required: APIAuth
) → Response

function plugin_api_internal_error

plugin_api_internal_error(trace: str) → Response

class APIAuth

An enumeration.


class AuthUser

method __init__

__init__(is_authenticated: bool, user: Optional[str], auth_role: APIAuth)

module configs

module configs.startup_config

Copyright 2022 SeaTalk Open Platform

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Global Variables

  • DEFAULT_STARTUP_CONFIG

class DBConfig

DBConfig address: address to the database mysql: TODO sqlite: sqlite://path_to_your_db.db

driver: "mysql" or "sqlite" are available


class RedisConfig

RedisConfig


class StartupConfig

Startup Config definition of the CSBot

module core

Copyright 2022 SeaTalk Open Platform

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.


class BaseBot

method __init__

__init__(config: Optional[StartupConfig] = None)

method get_app

get_app()

method on_event

on_event()

method register_adapter

register_adapter(adapter: BaseAdapter)

method run

run(host: str, port: int)

Runs the application on a local development server. :return: None


class CSBot

method __init__

__init__(
    config: Optional[StartupConfig] = StartupConfig(db=DBConfig(database='cs_bot.db', port=0, host='127.0.0.1', user='', password='', driver='sqlite', need_migration=False), redis=RedisConfig(host='127.0.0.1', port=6379, db=0), jwt_secret='', adapter={}, callback_path='/callback', signing_secret='', max_scheduler_workers=4, max_msg_handler_workers=32, owner_emails=[], developers=[], webhooks=[], debug=False)
)

property lifecycle


property scheduler


method get_app

get_app()

method get_fsm

get_fsm(key: Union[str, Type[ForwardRef('State')]]) → FSM

method on_event

on_event()

method register_adapter

register_adapter(adapter: BaseAdapter)

method register_fsm

register_fsm(fsm_name: str, state_class: Type[ForwardRef('State')]) → FSM

method reply

reply(
    event: EventChatMessage,
    message: Union[str, Message],
    quote_reply: bool = False
)

method run

run(host: str, port: int)

Runs the application on a local development server. :return: None


method send

send(receiver_email: Union[str, List[str]], message: Union[str, Message])

method send_group

send_group(
    group_name: str,
    message: Union[str, Message],
    mentioned_emails: Optional[List[str]] = None
)

method webhook

webhook(
    message: Union[str, bytes],
    msg_type: WebhookMsgType = <WebhookMsgType.TEXT: 'text'>
)

module helper

Copyright 2022 SeaTalk Open Platform

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.


function md5

md5(v: str) → str

module hooks

module hooks.bot_lifecycle

Copyright 2022 SeaTalk Open Platform

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.


class BotLifecycle

BotLifecycle

method __init__

__init__()

method emit_startup

emit_startup()

Emit the init event, iterate all the callback functions and call. :return: None


method on_startup

on_startup() → Callable[[], Callable[, NoneType]]

on_init :return: a decorator to use to register an bot initialization callback :rtype: LifecycleHook_D

module hooks.matcher

Copyright 2022 SeaTalk Open Platform

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.


class Matcher

Base Matcher Definition A matcher has 3️ duties 1⃣️ To tell whether the session matches the rule. 2⃣️ To tell whether the session.role has permission to trigger the message process procedure. 3⃣️ Process the message.

method __init__

__init__(
    rule: Callable[[ForwardRef('Session')], bool],
    permission: Optional[Permission],
    priority: int,
    processor: Callable[[ForwardRef('MessageSession')], NoneType]
)

init a new matcher / message process procedure :param rule: A function to tell whether a matcher is matched with the input session. :param permission: Used to judge whether a session has the permission to trigger a specified matcher. :param priority: priority decides the execution order of all matched matchers. :param processor: the function to call to process the incoming session.


method process

process(session: MessageSession)

Process the incoming session, where the real logic should be set :param session: the incoming session :return: None


method test

test(session: MessageSession) → bool

tell whether the session match the current matcher :param session: the incoming session :return: True on matched otherwise False

module libs

module libs.seatalk_openapi

module libs.seatalk_openapi.client

Copyright 2022 SeaTalk Open Platform

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Global Variables

  • API_GET_ACCESS_TOKEN
  • API_GET_CONTACT_PROFILE_V2
  • API_SEND_SINGLE_CHAT
  • API_GET_EMPLOYEE_CODE_WITH_EMAIL_V2
  • API_SEND_SERVICE_NOTICE
  • API_GET_DEPARTMENT_EMPLOYEES
  • API_GET_DEPARTMENTS
  • OK
  • ACCESS_TOKEN_EXPIRED
  • RATE_LIMIT
  • SECRET_INVALID

class API

method __init__

__init__(path: str, method: str)

class Employee


class ContactProfiles


class ServiceNoticeAlert


class ServiceNoticeButton


class ServiceNoticeMessage


class SeaTalkOpenAPIClient

Client implementation for the SeaTalk Open Platform Server API. See details in https://open.seatalk.io/docs/api-development-guide_

method __init__

__init__(app_id: str, app_secret: str, company_key: str = '')

method get_access_token

get_access_token()

method get_contact_profile_v2

get_contact_profile_v2(employee_code_list: List[str]) → ContactProfiles

Use this API to obtain an employee's basic profile information. See details in https://open.seatalk.io/docs/get-employee-profile :param employee_code_list: a list of employee codes :return: ContactProfiles instance contains profiles of all the valid and scoped employees.


method get_employee_code_with_email

get_employee_code_with_email(emails: List[str]) → Dict[str, str]

Use this API to exchange a user's email for employee_code. Only employee whose status is in-position(2) would be returned by this method. See details in https://open.seatalk.io/docs/get-employee-code-with-email. :param emails: emails to exchange :return: A dict, email as the key and the respective employee_code as the value.


method refresh_access_token

refresh_access_token()

Get app access token, see details in https://open.seatalk.io/docs/get-app-access-token :return: None


method request

request(
    api: API,
    json: Dict = None,
    query: Dict = None,
    with_auth_header: bool = True
) → Dict

method send_group_chat_message

send_group_chat_message(
    group_code: str,
    content: Union[str, bytes],
    content_type: str = 'text',
    mention_all: bool = False,
    mentioned_emails: Optional[List[str]] = None,
    mentioned_employee_codes: Optional[List[str]] = None
)

method send_service_notice

send_service_notice(
    employee_codes: List[str],
    messages: Dict[str, ServiceNoticeMessage],
    default_language: str = ''
) → Dict[str, str]

See details in https://open.seatalk.io/docs/messaging_send-service-notice_i18n


method send_single_chat_message

send_single_chat_message(
    employee_code: str,
    content: Union[str, bytes],
    content_type: str = 'text'
)

Let the bot send a single chat message to its subscriber. See details in https://open.seatalk.io/docs/messaging_send-message-to-bot-subscriber_ :param employee_code: target employee_code :param content: message content :param content_type: "text" and the "markdown" are available :return: None

module libs.seatalk_webhook

module libs.seatalk_webhook.client

Copyright 2022 SeaTalk Open Platform

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.


class WebhookMsgType

An enumeration.


class WebhookClient

method __init__

__init__(webhooks: List[str])

method send

send(
    message: Union[str, bytes],
    msg_type: WebhookMsgType = <WebhookMsgType.TEXT: 'text'>
)

module log

Copyright 2022 SeaTalk Open Platform

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Global Variables

  • logging: # Copyright 2001-2019 by Vinay Sajip. All Rights Reserved.

Permission to use, copy, modify, and distribute this software and its

documentation for any purpose and without fee is hereby granted,

provided that the above copyright notice appear in all copies and that

both that copyright notice and this permission notice appear in

supporting documentation, and that the name of Vinay Sajip

not be used in advertising or publicity pertaining to distribution

of the software without specific, written prior permission.

VINAY SAJIP DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING

ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL

VINAY SAJIP BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR

ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER

IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT

OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

Failed to generate docs for module metrics: ValueError("Duplicated timeseries in CollectorRegistry: {'cs_bot_message_handled_sum', 'cs_bot_message_handled', 'cs_bot_message_handled_count', 'cs_bot_message_handled_bucket', 'cs_bot_message_handled_created'}")

module models

module models.config

Copyright 2022 SeaTalk Open Platform

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Global Variables

  • TABLE_NAME_MAPPING

function table_name

table_name(model_class: Type[Model])

class PluginConfig


property dirty_fields


class KVRecord


property dirty_fields

module models.database

Copyright 2022 SeaTalk Open Platform

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.


function get_db

get_db() → DatabaseProxy

module permissions

Copyright 2022 SeaTalk Open Platform

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Global Variables

  • OWNER
  • DEVELOPER
  • ANYONE

class Permission

Permission is a rule to determined whether a message can trigger the specified Matcher.

method __init__

__init__(policy: Callable[[ForwardRef('Session')], bool])

method allow

allow(session: MessageSession) → bool

this method would be called to test whether the session has the permission to trigger the Matcher procedure. :param session: the incoming session to be tested :return: a bool value indicate the session has the permission or not

module plugin

Copyright 2022 SeaTalk Open Platform

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.


function filter_matchers

filter_matchers(sess: MessageSession) → List[Matcher]

class ConfigUpdateCallback

method __init__

__init__(
    f: Callable[[Type[ForwardRef('Config')]], NoneType],
    immediate: bool = False
)

class PluginLifecycle

method __init__

__init__()

method emit_config_updated

emit_config_updated(new, is_init: bool = False)

method emit_on_load

emit_on_load()

method emit_on_unload

emit_on_unload()

method on_load

on_load() → Callable[[], Callable[, NoneType]]

method on_plugin_config_update

on_plugin_config_update(
    immediate: bool = False
) → Callable[[Callable[[Type[ForwardRef('Config')]], NoneType]], Callable[[Type[ForwardRef('Config')]], NoneType]]

method on_unload

on_unload() → Callable[[], Callable[, NoneType]]

class PluginAPI

method __init__

__init__(handler: Callable[, Any], auth_role: APIAuth)

class Plugin

method __init__

__init__(
    module: module,
    name: str,
    lifecycle: PluginLifecycle,
    custom_api: Dict[str, Dict[str, PluginAPI]],
    config_class: Optional[Type[ForwardRef('Config')]],
    config,
    config_auto_sync: bool,
    exported_functions: Dict[str, Callable[[], Any]]
)

method get_api_handler

get_api_handler(api_path: str, method: str) → Optional[PluginAPI]

method get_exported_func

get_exported_func(function_name: str) → Optional[Callable[[], Any]]

method setup_auto_sync_lock

setup_auto_sync_lock()

method to_json

to_json() → Dict

method update_config

update_config(new_config: Dict) → None

class PluginManager


classmethod export

export(
    alias: Optional[str] = None
) → Callable[[Callable[[], Any]], Callable[[], Any]]

classmethod get_config

get_config(plugin_name: str) → Optional[Type[ForwardRef('Config')]]

classmethod get_plugin_by_name

get_plugin_by_name(plugin_name: str) → Optional[Plugin]

classmethod load_plugin

load_plugin(module_path: str) → Optional[Plugin]

classmethod on_any

on_any(permission: Optional[Permission], priority: int)

classmethod on_config_updated

on_config_updated(immediate: bool = False) → Callable[[Callable], Callable]

classmethod on_exact

on_exact(
    pattern: Union[str, List[str]],
    permission: Optional[Permission],
    priority: int
)

classmethod on_image

on_image(permission: Optional[Permission], priority: int)

classmethod on_keyword

on_keyword(
    keyword: Union[str, List[str]],
    permission: Optional[Permission],
    priority: int
)

classmethod on_plugin_loaded

on_plugin_loaded() → Callable[[Callable], Callable]

classmethod on_plugin_unloaded

on_plugin_unloaded() → Callable[[Callable], Callable]

classmethod on_prefix

on_prefix(
    prefix: Union[str, List[str]],
    permission: Optional[Permission],
    priority
) → Callable[[Callable[[ForwardRef('MessageSession')], NoneType]], Callable[[ForwardRef('MessageSession')], NoneType]]

classmethod on_regex

on_regex(
    pattern: Union[str, List[str]],
    permission: Optional[Permission],
    priority: int
)

classmethod register_plugin_api

register_plugin_api(
    path: str,
    methods: List[str],
    auth_role: APIAuth = <APIAuth.Anonymous: 0>
) → Callable[[Callable[, Any]], Callable[, Any]]

module protocol

Copyright 2022 SeaTalk Open Platform

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.


class EventType

An enumeration.


class MsgType

An enumeration.


class ChannelType

An enumeration.


class UserInfo


class GroupInfo


class Message

method __init__

__init__(
    content: Union[str, bytes],
    msg_type: MsgType = <MsgType.TEXT: 'text'>,
    **kwargs
)

class QuoteMessage


class EventChatMessage

pass


class EventNewSubscriber


class CallbackMessage


class SendMessageRequest

module role

Copyright 2022 SeaTalk Open Platform

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.


class BaseRole

method __init__

__init__(bot: 'CSBot', user_info: UserInfo)

classmethod extract_from

extract_from(bot: 'CSBot', event: CallbackMessage)

method is_developer

is_developer() → bool

method is_owner

is_owner() → bool

class Role

method __init__

__init__(bot: 'CSBot', user_info: UserInfo)

classmethod extract_from

extract_from(bot: 'CSBot', event: CallbackMessage)

method is_developer

is_developer() → bool

method is_owner

is_owner() → bool

module rule

Copyright 2022 SeaTalk Open Platform

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.


function rule_template

rule_template(
    word: Union[str, List[str]],
    f: Callable[[List[str], str], bool]
) → Callable[[ForwardRef('Session')], bool]

function rule_on_prefix

rule_on_prefix(
    prefix: Union[str, List[str]]
) → Callable[[ForwardRef('Session')], bool]

function rule_on_regex

rule_on_regex(
    regex: Union[str, List[str]]
) → Callable[[ForwardRef('Session')], bool]

function rule_on_keyword

rule_on_keyword(
    keyword: Union[str, List[str]]
) → Callable[[ForwardRef('Session')], bool]

function rule_on_exact

rule_on_exact(
    keyword: Union[str, List[str]]
) → Callable[[ForwardRef('Session')], bool]

module scheduler

Copyright 2022 SeaTalk Open Platform

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.


class Scheduler

method __init__

__init__(background_workers: int = 16)

property idle_seconds

:return: Number of seconds until :meth:next_run <Scheduler.next_run> or None if no jobs are scheduled


property next_run

Datetime when the next job should run.

:return: A :class:~datetime.datetime object or None if no jobs scheduled


property pool


method every

every(interval: int = 1) → Job

method run_pending

run_pending()

class Job

method __init__

__init__(interval: int, scheduler: Scheduler = None)

property day


property days


property friday


property hour


property hours


property minute


property minutes


property monday


property saturday


property second


property seconds


property should_run

:return: True if the job should be run now.


property sunday


property thursday


property tuesday


property wednesday


property week


property weeks


method at

at(time_str)

method background_job_wrapper

background_job_wrapper(f: Callable) → Callable

method block_do

block_do(job_func: Callable, *args, **kwargs)

method do

do(job_func: Callable, *args, **kwargs)

method once

once(job_func: Callable, *args, **kwargs)

method tag

tag(*tags: Hashable)

method to

to(latest: int)

method until

until(until_time: Union[datetime, timedelta, time, str])

module session

Copyright 2022 SeaTalk Open Platform

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.


class State

An enumeration.


class FSM

method __init__

__init__(bot: 'CSBot', fsm_name: str, state_class: Type[ForwardRef('State')])

method clear_state

clear_state(customer_email: str) → Tuple[Optional[State], bool]

Reset the state to the default_state for the specified user :param customer_email: email :return: Tuple (previous_state, removed or not)


method get_state

get_state(custom_email: str) → <enum 'State'>

method handle_time_out

handle_time_out() → Callable[[Callable[[str, ForwardRef('State')], Optional[Tuple[ForwardRef('State'), int]]]], Callable[[str, ForwardRef('State')], Optional[Tuple[ForwardRef('State'), int]]]]

method maintain_states

maintain_states()

method remove_expired_states

remove_expired_states() → Iterable[Tuple[str, State]]

Remove all the timeout states from the ZSET and trigger the FSM timeout handler. :return: an Iterable object of Tuple (email: str, previous_state: State)


method state_key

state_key(email: str) → str

method store_state

store_state(customer_email: str, state: State, timeout: int)

class BaseSession

method __init__

__init__(
    bot: 'CSBot',
    event: CallbackMessage,
    session_manager: 'SessionManager'
)

property aborted


property event


property state


method abort

abort()

method stop

stop()

class MessageSession

method __init__

__init__(
    bot: 'CSBot',
    event: CallbackMessage,
    session_manager: 'SessionManager'
)

property aborted


property event


property id


property last_message_time


property state


method abort

abort()

method get_state

get_state(state_class: Union[Type[ForwardRef('State')], str]) → State

method reply

reply(message: Union[str, Message], quote_reply: bool = False)

method send

send(receiver_email: Union[str, List[str]], message: Union[str, Message])

method stop

stop()

class FriendListChangeSession

method __init__

__init__(bot: 'CSBot', cm: CallbackMessage, session_manager: 'SessionManager')

property aborted


property event


property state


method abort

abort()

method stop

stop()

class SessionManager

method __init__

__init__(cache_manager: CacheManager)

module store

Copyright 2022 SeaTalk Open Platform

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Global Variables

  • TABLE_NAME_MAPPING

class ReconnectMySQLDatabase


class Storage


classmethod delete

delete(key: str) → bool

classmethod get

get(key: str) → Optional[str]

classmethod init

init(config: DBConfig)

classmethod init_migration

init_migration()

classmethod range

range(
    start_key: str,
    end_key: str,
    include_start_key: bool = True,
    include_end_key: bool = True
) → Iterable[Tuple[str, str]]

classmethod set

set(key: str, value: str)