///
/**
* Wechaty Chatbot SDK - https://github.com/wechaty/wechaty
*
* @copyright 2016 Huan LI (李卓桓) , and
* Wechaty Contributors .
*
* 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
*
* http://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.
*
*/
import { EventEmitter } from 'events';
import * as PUPPET from '@juzi/wechaty-puppet';
import type { Constructor } from 'clone-class';
import type { Accepter } from '../schemas/acceptable.js';
import type { ContactInterface } from './contact.js';
import type { RoomInterface } from './room.js';
interface FriendshipAddOptionsObject {
room?: RoomInterface;
contact?: ContactInterface;
hello?: string;
}
declare type FriendshipAddOptions = string | FriendshipAddOptionsObject;
declare const MixinBase: ((abstract new (...args: any[]) => {
readonly wechaty: import("../wechaty/wechaty-impl.js").WechatyInterface;
}) & {
readonly wechaty: import("../wechaty/wechaty-impl.js").WechatyInterface;
}) & typeof EventEmitter;
/**
* Send, receive friend request, and friend confirmation events.
*
* 1. send request
* 2. receive request(in friend event)
* 3. confirmation friendship(friend event)
*
* [Examples/Friend-Bot]{@link https://github.com/wechaty/wechaty/blob/1523c5e02be46ebe2cc172a744b2fbe53351540e/examples/friend-bot.ts}
*/
declare class FriendshipMixin extends MixinBase implements Accepter {
readonly id: string;
static Type: typeof PUPPET.types.Friendship;
/**
* @ignore
*/
static load(id: string): FriendshipInterface;
/**
* Search a Friend by phone or weixin.
*
* The best practice is to search friend request once per minute.
* Remember not to do this too frequently, or your account may be blocked.
*
* @param {FriendshipSearchCondition} condition - Search friend by phone or weixin.
* @returns {Promise}
*
* @example
* const friend_phone = await bot.Friendship.search({phone: '13112341234'})
* const friend_weixin = await bot.Friendship.search({weixin: 'weixin_account'})
*
* console.log(`This is the new friend info searched by phone : ${friend_phone}`)
* await bot.Friendship.add(friend_phone, 'hello')
*
*/
static search(queryFilter: PUPPET.filters.Friendship, type?: PUPPET.types.Contact): Promise;
/**
* Send a Friend Request to a `contact` with message `hello`.
*
* The best practice is to send friend request once per minute.
* Remeber not to do this too frequently, or your account may be blocked.
*
* @param {ContactInterface} contact - Send friend request to contact
* @param {FriendshipAddOptions} options - The friend request content
* @returns {Promise}
*
* @example
* const contact = await bot.Friendship.search({phone: '13112341234'})
* await bot.Friendship.add(contact, 'Nice to meet you! I am wechaty bot!')
*
* const memberList = await room.memberList()
* for (let i = 0; i < memberList.length; i++) {
* await bot.Friendship.add(member, {
* room: room,
* hello: `Nice to meet you! I am wechaty bot from room: ${await room.topic()}!`,
* })
* }
*
*/
static add(contact: ContactInterface, options: FriendshipAddOptions): Promise;
static del(contact: ContactInterface): Promise;
/**
*
* Instance Properties
*
*/
/**
* @ignore
*/
payload?: PUPPET.payloads.Friendship;
constructor(id: string);
toString(): string;
isReady(): boolean;
/**
* no `dirty` support because Friendship has no rawPayload(yet)
* @ignore
*/
ready(): Promise;
/**
* Accept Friend Request
*
* @returns {Promise}
*
* @example
* const bot = new Wechaty()
* bot.on('friendship', async friendship => {
* try {
* console.log(`received friend event.`)
* switch (friendship.type()) {
*
* // 1. New Friend Request
*
* case Friendship.Type.Receive:
* await friendship.accept()
* break
*
* // 2. Friend Ship Confirmed
*
* case Friendship.Type.Confirm:
* console.log(`friend ship confirmed`)
* break
* }
* } catch (e) {
* console.error(e)
* }
* }
* .start()
*/
accept(): Promise;
/**
* Get verify message from
*
* @returns {string}
* @example If request content is `ding`, then accept the friendship
* const bot = new Wechaty()
* bot.on('friendship', async friendship => {
* try {
* console.log(`received friend event from ${friendship.contact().name()}`)
* if (friendship.type() === Friendship.Type.Receive && friendship.hello() === 'ding') {
* await friendship.accept()
* }
* } catch (e) {
* console.error(e)
* }
* }
* .start()
*/
hello(): string;
/**
* Get the contact from friendship
*
* @returns {ContactInterface}
* @example
* const bot = new Wechaty()
* bot.on('friendship', async friendship => {
* const contact = friendship.contact()
* const name = contact.name()
* console.log(`received friend event from ${name}`)
* }
* .start()
*/
contact(): ContactInterface;
/**
* Return the Friendship Type
* > Tips: FriendshipType is enum here.
* - FriendshipType.Unknown
* - FriendshipType.Confirm
* - FriendshipType.Receive
* - FriendshipType.Verify
*
* @returns {FriendshipType}
*
* @example If request content is `ding`, then accept the friendship
* const bot = new Wechaty()
* bot.on('friendship', async friendship => {
* try {
* if (friendship.type() === Friendship.Type.Receive && friendship.hello() === 'ding') {
* await friendship.accept()
* }
* } catch (e) {
* console.error(e)
* }
* }
* .start()
*/
type(): PUPPET.types.Friendship;
/**
* get friendShipPayload Json
* @returns {FriendshipPayload}
*
* @example
* const bot = new Wechaty()
* bot.on('friendship', async friendship => {
* try {
* // JSON.stringify(friendship) as well.
* const payload = await friendship.toJSON()
* } catch (e) {
* console.error(e)
* }
* }
* .start()
*/
toJSON(): string;
/**
* create friendShip by friendshipJson
* @example
* const bot = new Wechaty()
* bot.start()
*
* const payload = '{...}' // your saved JSON payload
* const friendship = bot.FriendShip.fromJSON(friendshipFromDisk)
* await friendship.accept()
*/
static fromJSON(payload: string | PUPPET.payloads.Friendship): Promise;
}
declare const FriendshipImpl_base: {
new (...args: any[]): {};
valid: (o: any) => o is FriendshipInterface;
validInstance: (target: any) => target is FriendshipMixin;
validInterface: (target: any) => target is FriendshipInterface;
} & typeof FriendshipMixin;
declare class FriendshipImpl extends FriendshipImpl_base {
}
interface FriendshipInterface extends FriendshipImpl {
}
declare type FriendshipConstructor = Constructor;
export type { FriendshipConstructor, FriendshipInterface, };
export { FriendshipImpl, };
//# sourceMappingURL=friendship.d.ts.map