-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add GetSenderInfo function to get message sender info
- Loading branch information
1 parent
ceff03e
commit ef763dc
Showing
6 changed files
with
121 additions
and
1 deletion.
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
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"` | ||
} |