Cannot find documentation for botframework-connector functions examples

Viewed 61

I'm using the botframework-connector npm package. And I want to use the sendOperationRequest & sendRequest methods from the ConnectorClient instance.

I have searched for the method examples here but can not find them.

Can anyone help me, please?

Edit:

I know how to use the create/update conversations via Conversations methods. I'm trying to scope whether I can use the package for other operations such as createChannel, add members to a group etc.

1 Answers

You should explore code samples in

https://github.com/microsoft/BotBuilder-Samples/tree/main/samples

rather than trying to understand how to use the SDK through the class references. sendOperationRequest & sendRequest aren't really meant to be used explicitly, ConnectorClient uses it to send the request.

In order to send your message you first need a conversation reference (otherwise, how would the bot know which conversation to send the message to?) For example, look at the sample code on the documentation page of the NPM package you linked :

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);
}

The botID and recipientID is dependent on the channel you use.

Edit : As I misunderstood the intent of the question.

If you want to create a channel, check out https://github.com/howdyai/botkit/blob/main/packages/docs/core.md

There are officially supported channels with adapters that you can utilize. But if you are looking to connect to a custom app, look at https://github.com/howdyai/botkit/blob/main/packages/docs/reference/web.md#webadapter

for the generic web adapter that you can use to send and receive messages.

Related