wechaty-authing
v1.0.9
Published
wechaty-authing 主要用于 Wechaty 开发者将 Wechaty 的 Contact、Room 同步到 Authing 进行统一的管理。
Downloads
25
Readme
wechaty-authing
- wechaty-authing
- Usage
- Constructor
- protected client
- protected createAuthingUser(contact: Contact): Promise<User | null>;
- getPoolName(): Promise;
- filterAuthingUsers(contacts: Contact[]): Promise<ContactsFilterResult>;
- createAuthingUsers(contacts: Contact[]): Promise<ContactsOperationResult>;
- deleteAuthingUsers(contacts: Contact[]): Promise<ContactsOperationResult>;
- bindAuthingPhone(contact: Contact, phone: string): Promise;
- checkPhone(phone: string): Promise;
- bindPhoneContact(phone: string, contact: Contact): Promise;
- checkEmail(email: string): Promise;
- bindEmailContact(email: string, contact: Contact): Promise;
- Utils
- LICENSE
- Usage
Usage
POC Example: https://github.com/Authing/wechaty-authing-poc
Constructor
Params: WechatyAuthingConfig | ManagementClientOptions
Ref docs: https://docs.authing.cn/v2/reference/sdk-for-node/
Example:
import { WechatyAuthing, type WechatyAuthingConfig } from 'wechaty-authing';
const config: WechatyAuthingConfig = {
userPoolId: 'xxxxxxxxxx',
secret: 'xxxxxxxxxxx'
};
const authing = WechatyAuthing(config);
protected client
Returns: ManagementClient
Which is an Authing SDK client
protected createAuthingUser(contact: Contact): Promise<User | null>;
Create a Authing user
Params: Contact
Returns: User | null
getPoolName(): Promise;
Get Authing User pool name
const authing = WechatyAuthing(config);
await authing.getPoolName(); // '我的企业'
filterAuthingUsers(contacts: Contact[]): Promise<ContactsFilterResult>;
Batch check users exists from Authing
Params: Contact[]
Returns:
type ContactsFilterResult = {
registered: Contact[];
unregistered: Contact[];
fail: Contact[];
};
createAuthingUsers(contacts: Contact[]): Promise<ContactsOperationResult>;
Batch create users to Authing
Params: Contact[]
Returns:
type ContactsOperationResult = {
success: Contact[];
fail: Contact[];
};
deleteAuthingUsers(contacts: Contact[]): Promise<ContactsOperationResult>;
Batch delete users from Authing
Params and Return values are same with the create function.
bindAuthingPhone(contact: Contact, phone: string): Promise;
Create or update a authing user with Wechaty contact and phone
Params:
Contact
string
Returns: boolean
checkPhone(phone: string): Promise;
Check if user with the phone number exists in Authing
Params: string
Returns: boolean
bindPhoneContact(phone: string, contact: Contact): Promise;
Bind Wechaty contact to a Authing user by phone number
Params:
string
Contact
Returns: boolean
checkEmail(email: string): Promise;
Check if user with the email exists in Authing
Params: string
Returns: boolean
bindEmailContact(email: string, contact: Contact): Promise;
Bind Wechaty contact to a Authing user by email
Params:
string
Contact
Returns: boolean
Utils
getAuthingGender: (gender: any) => string
Convert Wechaty ContactGender to Authing Gender format
import { getAuthingGender } from 'wechaty-authing';
getAuthingGender(contact.gender()); // ContactGender.Unknown --> U
getContactId: (contact: any) => string
Get Valid Contact ID
import { getContactId } from 'wechaty-authing';
getContactId(contact); // weixin or empty string
arrayDiff: <T = Contact>(arr: T[], diff: T[]) => T[]
Array Set Difference
import { arrayDiff } from 'wechaty-authing';
arrayDiff([contact1, contact2, contact3], [contact2, contact3, contact4]);
// [contact1]
LICENSE
Apache 2.0