我使用的是botframework-connector
npm包。我想用sendOperationRequest
&sendRequest
方法从ConnectorClient
实例。
我已经搜索了这里的方法示例,但无法找到它们。
有谁能帮帮我吗?编辑:
我知道如何使用创建/更新对话通过Conversations
方法。我正试图确定我是否可以将包用于其他操作,如createChannel,向组添加成员等。
您应该探索
中的代码示例https://github.com/microsoft/BotBuilder-Samples/tree/main/samples
而不是试图通过类引用来理解如何使用SDK。sendOperationRequest
,sendRequest
不是真正要显式使用的,ConnectorClient使用它来发送请求。
为了发送消息,您首先需要一个会话引用(否则,bot如何知道将消息发送到哪个会话?)例如,查看你所链接的NPM包的文档页面上的示例代码:
var { ConnectorClient, MicrosoftAppCredentials } = require('botframework-connector');
async function connectToSlack() {
var credentials = new MicrosoftAppCredentials('<your-app-id>', '<your-app-password>');
var botId = '<bot-id>';
var recipientId = '<user-id>';
var client = new ConnectorClient(credentials, { baseUri: 'https://slack.botframework.com' });
var conversationResponse = await client.conversations.createConversation({
bot: { id: botId },
members: [
{ id: recipientId }
],
isGroup: false
});
var activityResponse = await client.conversations.sendToConversation(conversationResponse.id, {
type: 'message',
from: { id: botId },
recipient: { id: recipientId },
text: 'This a message from Bot Connector Client (NodeJS)'
});
console.log('Sent reply with ActivityId:', activityResponse.id);
}
botID和recipientID取决于您使用的通道。
编辑:因为我误解了问题的意图。如果您想创建一个频道,请签出https://github.com/howdyai/botkit/blob/main/packages/docs/core.md
有官方支持的带有适配器的通道可供您使用。但如果你想连接到一个自定义应用程序,看看https://github.com/howdyai/botkit/blob/main/packages/docs/reference/web.md#webadapter
为可用于发送和接收消息的通用web适配器。