Skip to content

Commit bd456a4

Browse files
committed
Merge branch 'master' of github.com:wechaty/python-wechaty
2 parents c0644cc + 909d2db commit bd456a4

File tree

5 files changed

+243
-504
lines changed

5 files changed

+243
-504
lines changed
Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,28 @@
1-
# 各种协议
2-
>这里应该是介绍各种协议存在的原因,通信原理等。以及可以分析一下不同协议使用的利弊等等。
1+
## 一、支持的协议
2+
3+
一个Wechaty实例/派生类就是机器人对象,能够根据`TOKEN`找到连接的服务,获取用户自模块执行搜索,而这些信息都是由Wechaty实例管理。
4+
5+
> 由于服务的连接信息是保存到实例当中,故用户子模块一定要通过Wechaty实例来获取。例如:bot.Contact.find_all()
6+
7+
### 1.1 什么是协议
8+
9+
所有实现底层平台对接实现就是一个协议。
10+
11+
python-wechaty理论上能够对接所有IM平台,目前已经对接微信、微信公众号、钉钉、飞书以及WhatsApp等平台,源码都是基于TypeScript语言,可是通过`wechaty-puppet-service`能够将其服务以gRPC的形式暴露出来,提供给多语言`Wechaty`来连接。例如微信免费Web协议,底层实现是基于TyepScript编写,可是通过社区生态项目,可是都可以使用docker将接口的实现部署成服务。
12+
13+
比如[wechaty-puppet-wechat](https://github.com/wechaty/wechaty-puppet-wechat)能够通过[wechaty/wechaty:latest](https://hub.docker.com/r/wechaty/wechaty)镜像将其所有实现接口暴露成gRPC的服务,非常的方便,已然实现`write once, run anywhere`
14+
15+
### 1.2 协议列表
16+
17+
目前python-wechaty能够使用wechaty生态中所有IM平台对接协议,协议列表如下所示:
18+
19+
* [wechaty-puppet-wechaty](https://github.com/wechaty/wechaty-puppet-wechat): 免费微信Web协议
20+
* [wechaty-puppet-](https://github.com/wechaty/wechaty-puppet-macOS): 免费微信MacOs协议
21+
* [wechaty-puppet-padlocal](https://github.com/wechaty/wechaty-puppet-padlocal): 付费微信Pad协议
22+
* [wechaty-puppet-official-account](https://github.com/wechaty/wechaty-puppet-official-account): 微信公众号协议
23+
* [wechaty-puppet-lark](https://github.com/wechaty/wechaty-puppet-lark): 飞书协议
24+
* [wechaty-puppet-dingtalk](https://github.com/wechaty/wechaty-puppet-dingtalk): 钉钉协议
25+
* [wechaty-puppet-teams](https://github.com/wechaty/wechaty-puppet-dingtalk): 微软Teams协议
26+
* ......
27+
28+

docs/references/friendship.md

Lines changed: 26 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,23 @@
22
title: Friendship
33
---
44

5-
发送、接收好友请求和好友确认事件。
5+
# class Friendship()
6+
> 发送、接收好友请求和好友确认事件。
7+
> [示例/Friend-Bot](https://github.com/wechaty/python-wechaty-getting-started/blob/master/examples/advanced/friendship-bot.py)
68
7-
## Friendship
89

9-
发送、接收好友请求和好友确认事件。
10+
::: wechaty.user.friendship.Friendship.search
1011

11-
1. 发送请求
12-
2. 接收请求\(in friend event\)
13-
3. 接受请求\(friend event\)
14-
15-
[示例/Friend-Bot](https://github.com/wechaty/python-wechaty-getting-started/blob/master/examples/advanced/friendship-bot.py)
16-
17-
**类型**: 全局类
18-
19-
* [Friendship](friendship.md#Friendship)
20-
* _实例方法_
21-
* [.accept\(\)](friendship.md#Friendship+accept)`None`
22-
* [.hello\(\)](friendship.md#Friendship+hello)`str`
23-
* [.contact\(\)](friendship.md#Friendship+contact)`Contact`
24-
* [.type\(\)](friendship.md#Friendship+type)`FriendshipType`
25-
* _静态方法_
26-
* [~~.send\(\)~~](friendship.md#Friendship.send)
27-
* [.add\(contact, hello\)](friendship.md#Friendship.add)`None`
28-
29-
### friendship.accept\(\)`None`
30-
31-
接受朋友请求
32-
33-
**类型**: [`Friendship`](friendship.md#Friendship)的实例方法
34-
35-
#### 示例
12+
::: wechaty.user.friendship.Friendship.add
13+
### 示例代码
14+
```python
15+
memberList = await room.memberList()
16+
for member in memberList:
17+
await bot.Friendship.add(member, 'Nice to meet you! I am wechaty bot!')
18+
```
3619

20+
::: wechaty.user.friendship.Friendship.contact
21+
### 示例代码
3722
```python
3823
import asyncio
3924
from wechaty import Wechaty, Friendship
@@ -44,97 +29,45 @@ class MyBot(Wechaty):
4429
async on_friendship(self, friendship: Friendship) -> None:
4530
contact = friendship.contact()
4631
await contact.ready()
47-
48-
if friendship.type() == FriendshipType.FRIENDSHIP_TYPE_RECEIVE:
49-
log_msg = 'accepted automatically'
50-
await friendship.accept()
51-
# if want to send msg, you need to delay sometimes
52-
53-
print('waiting to send message ...')
54-
await asyncio.sleep(3)
55-
await contact.say('hello from wechaty ...')
56-
print('after accept ...')
57-
elif friendship.type() == FriendshipType.FRIENDSHIP_TYPE_CONFIRM:
58-
log_msg = 'friend ship confirmed with ' + contact.name
59-
32+
log_msg = f'receive "friendship" message from {contact.name}'
6033
print(log_msg)
6134

35+
6236
asyncio.run(MyBot().start())
6337
```
6438

65-
### friendship.hello\(\)`str`
66-
67-
Get verify message from
68-
69-
**类型**: [`Friendship`](friendship.md#Friendship)的实例方法
70-
71-
**示例**
72-
73-
_\(If request content is \`ding\`, then accept the friendship\)_
74-
39+
::: wechaty.user.friendship.Friendship.accept
40+
### 示例代码
7541
```python
7642
import asyncio
7743
from wechaty import Wechaty, Friendship
7844

79-
8045
class MyBot(Wechaty):
8146

8247
async on_friendship(self, friendship: Friendship) -> None:
8348
contact = friendship.contact()
8449
await contact.ready()
8550

86-
if friendship.type() == FriendshipType.FRIENDSHIP_TYPE_RECEIVE and friendship.hello() == 'ding':
87-
log_msg = 'accepted automatically because verify messsage is "ding"'
51+
if friendship.type() == FriendshipType.FRIENDSHIP_TYPE_RECEIVE:
52+
log_msg = 'accepted automatically'
8853
await friendship.accept()
8954
# if want to send msg, you need to delay sometimes
9055

9156
print('waiting to send message ...')
9257
await asyncio.sleep(3)
9358
await contact.say('hello from wechaty ...')
9459
print('after accept ...')
60+
elif friendship.type() == FriendshipType.FRIENDSHIP_TYPE_CONFIRM:
61+
log_msg = 'friend ship confirmed with ' + contact.name
9562

96-
asyncio.run(MyBot().start())
97-
```
98-
99-
### friendship.contact\(\)`Contact`
100-
101-
获取邀请的联系人对象
102-
103-
**类型**: [`Friendship`](friendship.md#Friendship)的实例方法
104-
105-
#### 示例
106-
107-
```python
108-
import asyncio
109-
from wechaty import Wechaty, Friendship
110-
111-
112-
class MyBot(Wechaty):
113-
114-
async on_friendship(self, friendship: Friendship) -> None:
115-
contact = friendship.contact()
116-
await contact.ready()
117-
log_msg = f'receive "friendship" message from {contact.name}'
11863
print(log_msg)
11964

120-
12165
asyncio.run(MyBot().start())
12266
```
12367

124-
### friendship.type\(\)`FriendshipType`
125-
126-
返回Friendship请求的类型
127-
128-
> 提示: FriendshipType在这里是枚举类型. </br>
129-
>
130-
> * FriendshipType.FriendshipTypeFRIENDSHIP_TYPE_UNSPECIFIED
131-
> * FriendshipType.FRIENDSHIP_TYPE_CONFIRM
132-
> * FriendshipType.FRIENDSHIP_TYPE_RECEIVE
133-
> * FriendshipType.FRIENDSHIP_TYPE_VERIFY
134-
135-
**类型**: [`Friendship`](friendship.md#Friendship)的实例方法
136-
137-
**示例** _\(If request content is \`ding\`, then accept the friendship\)_
68+
::: wechaty.user.friendship.Friendship.hello
69+
### 示例代码
70+
> 自动接受好友请求中包含消息为 `ding` 的好友请求
13871
13972
```python
14073
import asyncio
@@ -160,32 +93,6 @@ class MyBot(Wechaty):
16093
asyncio.run(MyBot().start())
16194
```
16295

163-
### ~~Friendship.send\(\)~~
164-
165-
_**已弃用**_
166-
167-
请使用[Friendship\#add](friendship.md#friendship-add-contact-hello-promise)
168-
169-
**类型**: [`Friendship`](friendship.md#Friendship)的静态方法
170-
171-
### Friendship.add\(contact, hello\)`Promise <void>`
172-
173-
Send a Friend Request to a `contact` with message `hello`.
174-
175-
The best practice is to send friend request once per minute. Remeber not to do this too frequently, or your account may be blocked.
96+
::: wechaty.user.friendship.Friendship.type
17697

177-
**类型**: [`Friendship`](friendship.md#Friendship)的静态方法
178-
179-
| 参数 | 类型 | 描述 |
180-
| :--- | :--- | :--- |
181-
| contact | `Contact` | Send friend request to contact |
182-
| hello | `string` | The friend request content |
183-
184-
#### Example
185-
186-
```python
187-
memberList = await room.memberList()
188-
for member in memberList:
189-
await bot.Friendship.add(member, 'Nice to meet you! I am wechaty bot!')
190-
191-
```
98+
::: wechaty.user.friendship.Friendship.from_json

0 commit comments

Comments
 (0)