-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add GetSenderInfo function to get message sender info #58
Open
risboo6909
wants to merge
1
commit into
infracloudio:develop
Choose a base branch
from
risboo6909:get_member_info
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package activity | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"net/url" | ||
"path" | ||
|
||
"github.com/infracloudio/msbotbuilder-go/schema" | ||
"github.com/pkg/errors" | ||
) | ||
|
||
const getMemberInfo = "/%s/conversations/%s/members/%s" | ||
|
||
// GetSenderInfo get conversation member info. | ||
func (response *DefaultResponse) GetSenderInfo(activity schema.Activity) (*schema.ConversationMember, error) { | ||
u, err := url.Parse(activity.ServiceURL) | ||
if err != nil { | ||
return nil, errors.Wrapf(err, "Failed to parse ServiceURL %s.", activity.ServiceURL) | ||
} | ||
|
||
urlString := fmt.Sprintf(getMemberInfo, APIVersion, activity.Conversation.ID, activity.From.ID) | ||
|
||
u.Path = path.Join(u.Path, urlString) | ||
raw, err := response.Client.Get(*u) | ||
if err != nil { | ||
return nil, errors.Wrap(err, "Failed to get response.") | ||
} | ||
|
||
var convMember schema.ConversationMember | ||
|
||
err = json.Unmarshal(raw, &convMember) | ||
if err != nil { | ||
return nil, errors.Wrap(err, "Failed to parse response.") | ||
} | ||
|
||
return &convMember, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -34,6 +34,7 @@ import ( | |||||||
// Adapter is the primary interface for the user program to perform operations with | ||||||||
// the connector service. | ||||||||
type Adapter interface { | ||||||||
GetSenderInfo(ctx context.Context, req schema.Activity) (*schema.ConversationMember, error) | ||||||||
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 | ||||||||
|
@@ -84,6 +85,22 @@ func NewBotAdapter(settings AdapterSetting) (Adapter, error) { | |||||||
return &BotFrameworkAdapter{settings, auth.NewJwtTokenValidator(), connectorClient}, nil | ||||||||
} | ||||||||
|
||||||||
// GetSenderInfo returns information about message sender. | ||||||||
func (bf *BotFrameworkAdapter) GetSenderInfo(ctx context.Context, req schema.Activity) (*schema.ConversationMember, error) { | ||||||||
response, err := activity.NewActivityResponse(bf.Client) | ||||||||
if err != nil { | ||||||||
return nil, errors.Wrap(err, "Failed to create response object.") | ||||||||
} | ||||||||
|
||||||||
resp, err := response.GetSenderInfo(req) | ||||||||
if err != nil { | ||||||||
return nil, errors.Wrap(err, "Failed to get data.") | ||||||||
} | ||||||||
|
||||||||
return resp, nil | ||||||||
|
||||||||
Comment on lines
+99
to
+101
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
[nit] unnecessary new lines |
||||||||
} | ||||||||
|
||||||||
// ProcessActivity receives an activity, processes it as specified in by the 'handler' and | ||||||||
// sends it to the connector service. | ||||||||
func (bf *BotFrameworkAdapter) ProcessActivity(ctx context.Context, req schema.Activity, handler activity.Handler) error { | ||||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package schema | ||
|
||
// ConversationMember - Conversation member info | ||
type ConversationMember struct { | ||
|
||
// Member ID | ||
ID string `json:"id,omitempty"` | ||
|
||
// Display friendly name | ||
Name string `json:"name,omitempty"` | ||
|
||
// GivenName | ||
GivenName string `json:"givenName,omitempty"` | ||
|
||
// Surname | ||
Surname string `json:"surname,omitempty"` | ||
|
||
// This account's object ID within Azure Active Directory (AAD) | ||
AadObjectID string `json:"aadObjectId,omitempty"` | ||
|
||
// Email is user email | ||
Email string `json:"email,omitempty"` | ||
|
||
// UserPrincipalName | ||
UserPrincipalName string `json:"userPrincipalName,omitempty"` | ||
|
||
// TenantID is an ID fo a tenant | ||
TenantID string `json:"tenantId,omitempty"` | ||
|
||
// UserRole is a user role | ||
UserRole RoleTypes `json:"userRole,omitempty"` | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we use
client.sendRequest()
method to avoid duplicate code?