core

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 12, 2021 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package core is the entry point and the main interface for a user program.

It provides an adapter to the user program using which all the operations can be made on this SDK. See the example to understand how to use this package to perform operations on the Bot Framwework connector service.

Example
package main

import (
	"context"
	"fmt"
	"log"
	"os"

	"dev.azure.com/fmonod/Bot-Builder/_git/msbotbuilder-go/core"
	"dev.azure.com/fmonod/Bot-Builder/_git/msbotbuilder-go/core/activity"
	"dev.azure.com/fmonod/Bot-Builder/_git/msbotbuilder-go/schema"
)

func main() {

	// Load settings from environment variables to AdapterSetting.
	setting := core.AdapterSetting{
		AppID:       os.Getenv("APP_ID"),
		AppPassword: os.Getenv("APP_PASSWORD"),
	}

	// Make an adapter to perform operations with the Bot Framework using this library.
	adapter, err := core.NewBotAdapter(setting)
	if err != nil {
		log.Fatal(err)
	}

	// Create a handler that defines operations to be performed on respective events.
	// Following defines the operation to be performed on the 'message' event.
	var customHandler = activity.HandlerFuncs{
		OnMessageFunc: func(turn *activity.TurnContext) (schema.Activity, error) {
			return turn.SendActivity(activity.MsgOptionText("Echo: " + turn.Activity.Text))
		},
	}

	// activity depicts a request as received from a client
	activity := schema.Activity{
		Type: schema.Message,
		From: schema.ChannelAccount{
			ID:   "12345678",
			Name: "Pepper's News Feed",
		},
		Conversation: schema.ConversationAccount{
			ID:   "abcd1234",
			Name: "Convo1",
		},
		Recipient: schema.ChannelAccount{
			ID:   "1234abcd",
			Name: "SteveW",
		},
		Text:      "Message from Teams Client",
		ReplyToID: "5d5cdc723",
	}

	// Pass the activity and handler to the adapter for proecssing
	ctx := context.Background()
	err = adapter.ProcessActivity(ctx, activity, customHandler)
	if err != nil {
		fmt.Println("Failed to process request", err)
		return
	}
}
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Adapter

type Adapter interface {
	ParseRequest(ctx context.Context, req *http.Request) (schema.Activity, error)
	ProcessActivity(ctx context.Context, req schema.Activity, handler activity.Handler) error
	ProactiveMessage(ctx context.Context, ref schema.ConversationReference, handler activity.Handler) error
	DeleteActivity(ctx context.Context, activityID string, ref schema.ConversationReference) error
}

Adapter is the primary interface for the user program to perform operations with the connector service.

func NewBotAdapter

func NewBotAdapter(settings AdapterSetting) (Adapter, error)

NewBotAdapter creates and reuturns a new BotFrameworkAdapter with the specified AdapterSettings.

type AdapterSetting

type AdapterSetting struct {
	AppID              string
	AppPassword        string
	ChannelAuthTenant  string
	OauthEndpoint      string
	OpenIDMetadata     string
	ChannelService     string
	CredentialProvider auth.CredentialProvider
}

AdapterSetting is the configuration for the Adapter.

type BotFrameworkAdapter

type BotFrameworkAdapter struct {
	AdapterSetting
	auth.TokenValidator
	client.Client
}

BotFrameworkAdapter implements Adapter and is currently the only implementation returned to the user program.

func (*BotFrameworkAdapter) DeleteActivity

func (bf *BotFrameworkAdapter) DeleteActivity(ctx context.Context, activityID string, ref schema.ConversationReference) error

DeleteActivity Deletes an existing activity by Activity ID

func (*BotFrameworkAdapter) ParseRequest

func (bf *BotFrameworkAdapter) ParseRequest(ctx context.Context, req *http.Request) (schema.Activity, error)

ParseRequest parses the received activity in a HTTP reuqest to:

1. Validate the structure.

2. Authenticate the request (using authenticateRequest())

Returns an Activity value on successfull parsing.

func (*BotFrameworkAdapter) ProactiveMessage

func (bf *BotFrameworkAdapter) ProactiveMessage(ctx context.Context, ref schema.ConversationReference, handler activity.Handler) error

ProactiveMessage sends activity to a conversation. This methods is used for Bot initiated conversation.

func (*BotFrameworkAdapter) ProcessActivity

func (bf *BotFrameworkAdapter) ProcessActivity(ctx context.Context, req schema.Activity, handler activity.Handler) error

ProcessActivity receives an activity, processes it as specified in by the 'handler' and sends it to the connector service.

Directories

Path Synopsis
Package activity acts as a handler for any received activity and the user defined operation on that activity.
Package activity acts as a handler for any received activity and the user defined operation on that activity.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL