func (c *Command) CreateInvitation(rw io.Writer, req io.Reader) command.Error {
	var request CreateInvitationArgs
	err := json.NewDecoder(req).Decode(&request)
	if err != nil {
		logutil.LogInfo(logger, CommandName, CreateInvitationCommandMethod, err.Error())
		return command.NewValidationError(InvalidRequestErrorCode, err)
	}
	var invitation *didexchange.Invitation
	if request.Public != "" {
		invitation, err = c.client.CreateInvitationWithDID(c.defaultLabel, request.Public)
	} else {
		invitation, err = c.client.CreateInvitation(c.defaultLabel,
			didexchange.WithRouterConnectionID(request.RouterConnectionID))
	}
	if err != nil {
		logutil.LogError(logger, CommandName, CreateInvitationCommandMethod, err.Error())
		return command.NewExecuteError(CreateInvitationErrorCode, err)
	}
	command.WriteNillableResponse(rw, &CreateInvitationResponse{
		Invitation: invitation,
		Alias:      request.Alias,
	},
		logger)
	logutil.LogDebug(logger, CommandName, CreateInvitationCommandMethod, successString,
		logutil.CreateKeyValueString(invitationIDString, invitation.ID))
	return nil
}
CreateInvitation Creates a new connection invitation.
package didexchange
import (
	"encoding/json"
	"fmt"
	"io"
	"strings"
	"github.com/hyperledger/aries-framework-go/pkg/client/didexchange"
	"github.com/hyperledger/aries-framework-go/pkg/common/log"
	"github.com/hyperledger/aries-framework-go/pkg/controller/command"
	"github.com/hyperledger/aries-framework-go/pkg/controller/internal/cmdutil"
	"github.com/hyperledger/aries-framework-go/pkg/controller/webnotifier"
	"github.com/hyperledger/aries-framework-go/pkg/didcomm/common/service"
	protocol "github.com/hyperledger/aries-framework-go/pkg/didcomm/protocol/didexchange"
	"github.com/hyperledger/aries-framework-go/pkg/doc/did"
	"github.com/hyperledger/aries-framework-go/pkg/internal/logutil"
	"github.com/hyperledger/aries-framework-go/pkg/kms"
	"github.com/hyperledger/aries-framework-go/spi/storage"
)
var logger = log.New("aries-framework/controller/did-exchange")
const (
	CommandName = "didexchange"
	errEmptyInviterDID = "empty inviter DID"
	errEmptyConnID     = "empty connection ID"
	AcceptExchangeRequestCommandMethod    = "AcceptExchangeRequest"
	AcceptInvitationCommandMethod         = "AcceptInvitation"
	CreateImplicitInvitationCommandMethod = "CreateImplicitInvitation"
	CreateInvitationCommandMethod         = "CreateInvitation"
	QueryConnectionByIDCommandMethod      = "QueryConnectionByID"
	QueryConnectionsCommandMethod         = "QueryConnections"
	ReceiveInvitationCommandMethod        = "ReceiveInvitation"
	CreateConnectionCommandMethod         = "CreateConnection"
	RemoveConnectionCommandMethod         = "RemoveConnection"
	connectionIDString = "connectionID"
	successString      = "success"
	invitationIDString = "invitationID"
)
const (
	InvalidRequestErrorCode = command.Code(iota + command.DIDExchange)
	CreateInvitationErrorCode
	CreateImplicitInvitationErrorCode
	ReceiveInvitationErrorCode
	AcceptInvitationErrorCode
	AcceptExchangeRequestErrorCode
	QueryConnectionsErrorCode
	RemoveConnectionErrorCode
	CreateConnectionErrorCode
	_actions = "_actions"
	_states  = "_states"
)
type provider interface {
	Service(id string) (interface{}, error)
	KMS() kms.KeyManager
	ServiceEndpoint() string
	StorageProvider() storage.Provider
	ProtocolStateStorageProvider() storage.Provider
	KeyType() kms.KeyType
	KeyAgreementType() kms.KeyType
	MediaTypeProfiles() []string
}
func New(ctx provider, notifier command.Notifier, defaultLabel string, autoAccept bool) (*Command, error) {
	didExchange, err := didexchange.New(ctx)
	if err != nil {
		return nil, err
	}
	actions := make(chan service.DIDCommAction)
	if err := didExchange.RegisterActionEvent(actions); err != nil {
		return nil, fmt.Errorf("register action event: %w", err)
	}
	states := make(chan service.StateMsg)
	if err := didExchange.RegisterMsgEvent(states); err != nil {
		return nil, fmt.Errorf("register msg event: %w", err)
	}
	subscribers := []chan service.DIDCommAction{
		make(chan service.DIDCommAction),
	}
	if autoAccept {
		subscribers = append(subscribers, make(chan service.DIDCommAction))
		go service.AutoExecuteActionEvent(subscribers[1])
	}
	go func() {
		for action := range actions {
			for i := range subscribers {
				action.Message = action.Message.Clone()
				subscribers[i] <- action
			}
		}
	}()
	obs := webnotifier.NewObserver(notifier)
	obs.RegisterAction(protocol.DIDExchange+_actions, subscribers[0])
	obs.RegisterStateMsg(protocol.DIDExchange+_states, states)
	cmd := &Command{
		ctx:          ctx,
		client:       didExchange,
		msgCh:        make(chan service.StateMsg),
		defaultLabel: defaultLabel,
	}
	return cmd, nil
}
type Command struct {
	ctx          provider
	client       *didexchange.Client
	msgCh        chan service.StateMsg
	defaultLabel string
}
func (c *Command) GetHandlers() []command.Handler {
	return []command.Handler{
		cmdutil.NewCommandHandler(CommandName, CreateInvitationCommandMethod, c.CreateInvitation),
		cmdutil.NewCommandHandler(CommandName, ReceiveInvitationCommandMethod, c.ReceiveInvitation),
		cmdutil.NewCommandHandler(CommandName, AcceptInvitationCommandMethod, c.AcceptInvitation),
		cmdutil.NewCommandHandler(CommandName, CreateConnectionCommandMethod, c.CreateConnection),
		cmdutil.NewCommandHandler(CommandName, RemoveConnectionCommandMethod, c.RemoveConnection),
		cmdutil.NewCommandHandler(CommandName, QueryConnectionByIDCommandMethod, c.QueryConnectionByID),
		cmdutil.NewCommandHandler(CommandName, QueryConnectionsCommandMethod, c.QueryConnections),
		cmdutil.NewCommandHandler(CommandName, AcceptExchangeRequestCommandMethod, c.AcceptExchangeRequest),
		cmdutil.NewCommandHandler(CommandName, CreateImplicitInvitationCommandMethod, c.CreateImplicitInvitation),
	}
}