mirror of
https://github.com/PaiGramTeam/PaiGramDocs.git
synced 2024-11-22 07:07:47 +00:00
📝 Add plugin - create
This commit is contained in:
parent
f4d83d8fc0
commit
736b5dffd2
@ -32,6 +32,7 @@ export default {
|
||||
items: [
|
||||
{ text: '插件编写准备', link: '/plugin/start' },
|
||||
{ text: '插件写法', link: '/plugin/create' },
|
||||
{ text: '调用 Telegram 接口', link: '/plugin/bot' },
|
||||
],
|
||||
},
|
||||
],
|
||||
|
@ -17,18 +17,18 @@ const colorMap = {
|
||||
}
|
||||
|
||||
const avatarMap = {
|
||||
grambot: '',
|
||||
b: '',
|
||||
GrambBot: '/icon_256px.jpg',
|
||||
User: '/user.png',
|
||||
}
|
||||
|
||||
const typeMap = {
|
||||
grambot: 'tip',
|
||||
b: 'danger',
|
||||
GrambBot: 'tip',
|
||||
User: 'danger',
|
||||
}
|
||||
|
||||
const tagMap = {
|
||||
grambot: '机器人',
|
||||
b: '用户',
|
||||
GrambBot: '机器人',
|
||||
User: '用户',
|
||||
}
|
||||
|
||||
const shown = ref(false)
|
||||
|
34
docs/plugin/bot.md
Normal file
34
docs/plugin/bot.md
Normal file
@ -0,0 +1,34 @@
|
||||
# 调用 Telegram 接口
|
||||
|
||||
在 GramBot 中,我们可以通过 Bot 对象来调用 Telegram 支持的平台 API,来完成更多的功能。
|
||||
|
||||
## 获取 Bot 对象
|
||||
|
||||
```python
|
||||
async def start(self, update: Update, context: CallbackContext):
|
||||
bot = context.bot
|
||||
```
|
||||
|
||||
## 调用 API
|
||||
|
||||
```python
|
||||
# 向账号发送 你好
|
||||
await bot.send_message(777000, "你好")
|
||||
```
|
||||
|
||||
```python
|
||||
@handler.command(command='start', block=False)
|
||||
async def start(self, update: Update, context: CallbackContext):
|
||||
await update.effective_chat.send_message('hello world!')
|
||||
await bot.send_message(update.effective_user.id, "你好")
|
||||
```
|
||||
|
||||
<ChatPanel title="Telegram">
|
||||
<ChatMessage nickname="User">/start</ChatMessage>
|
||||
<ChatMessage nickname="GrambBot">hello world!</ChatMessage>
|
||||
<ChatMessage nickname="GrambBot">你好</ChatMessage>
|
||||
</ChatPanel>
|
||||
|
||||
## API 文档
|
||||
|
||||
https://docs.python-telegram-bot.org/en/v20.6/telegram.bot.html
|
@ -90,6 +90,11 @@ contributors: ["luoshuijs", "zhxycn"]
|
||||
await update.effective_chat.send_message('hello world!')
|
||||
```
|
||||
|
||||
<ChatPanel title="Telegram">
|
||||
<ChatMessage nickname="User">/start</ChatMessage>
|
||||
<ChatMessage nickname="GrambBot">hello world!</ChatMessage>
|
||||
</ChatPanel>
|
||||
|
||||
### 对于 `ConversationHandler`
|
||||
|
||||
由于 `ConversationHandler` 比较特殊,所以**一个 Plugin 类中只能存在一个 `ConversationHandler`**
|
||||
@ -112,11 +117,14 @@ class TestConversation(Plugin.Conversation, allow_reentry=True, block=False):
|
||||
@handler.command(command='entry')
|
||||
async def entry_point(self, update: Update, context: CallbackContext):
|
||||
"""do something"""
|
||||
await update.effective_chat.send_message('hello')
|
||||
return STATE_A
|
||||
|
||||
@conversation.state(state=STATE_A)
|
||||
@handler.message(filters=filters.TEXT)
|
||||
async def state(self, update: Update, context: CallbackContext):
|
||||
"""do something"""
|
||||
await update.effective_chat.send_message('world!')
|
||||
|
||||
@conversation.fallback
|
||||
@handler.message(filters=filters.TEXT)
|
||||
@ -129,6 +137,13 @@ class TestConversation(Plugin.Conversation, allow_reentry=True, block=False):
|
||||
|
||||
```
|
||||
|
||||
<ChatPanel title="Telegram">
|
||||
<ChatMessage nickname="User">/entry</ChatMessage>
|
||||
<ChatMessage nickname="GrambBot">hello</ChatMessage>
|
||||
<ChatMessage nickname="User">ok</ChatMessage>
|
||||
<ChatMessage nickname="GrambBot">world!</ChatMessage>
|
||||
</ChatPanel>
|
||||
|
||||
### 对于 `Job`
|
||||
|
||||
1. 依然需要继承 `core.plugin.Plugin`
|
||||
|
BIN
docs/public/user.png
Normal file
BIN
docs/public/user.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 754 KiB |
Loading…
Reference in New Issue
Block a user