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 ¶
- type Adapter
- type AdapterSetting
- type BotFrameworkAdapter
- func (bf *BotFrameworkAdapter) DeleteActivity(ctx context.Context, activityID string, ref schema.ConversationReference) error
- func (bf *BotFrameworkAdapter) ParseRequest(ctx context.Context, req *http.Request) (schema.Activity, error)
- func (bf *BotFrameworkAdapter) ProactiveMessage(ctx context.Context, ref schema.ConversationReference, ...) error
- func (bf *BotFrameworkAdapter) ProcessActivity(ctx context.Context, req schema.Activity, handler activity.Handler) error
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.