-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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 endpoints for calls.*
apis and Type: call
in blockkit
#1190
Open
winston-stripe
wants to merge
5
commits into
slack-go:master
Choose a base branch
from
winston-stripe:calls-api
base: master
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
Show all changes
5 commits
Select commit
Hold shift + click to select a range
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,23 @@ | ||
package slack | ||
|
||
// CallBlock defines data that is used to display a call in slack. | ||
// | ||
// More Information: https://api.slack.com/apis/calls#post_to_channel | ||
type CallBlock struct { | ||
Type MessageBlockType `json:"type"` | ||
BlockID string `json:"block_id,omitempty"` | ||
CallID string `json:"call_id"` | ||
} | ||
|
||
// BlockType returns the type of the block | ||
func (s CallBlock) BlockType() MessageBlockType { | ||
return s.Type | ||
} | ||
|
||
// NewFileBlock returns a new instance of a file block | ||
func NewCallBlock(callID string) *CallBlock { | ||
return &CallBlock{ | ||
Type: MBTCall, | ||
CallID: callID, | ||
} | ||
} |
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,13 @@ | ||
package slack | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestNewCallBlock(t *testing.T) { | ||
callBlock := NewCallBlock("ACallID") | ||
assert.Equal(t, string(callBlock.Type), "call") | ||
assert.Equal(t, callBlock.CallID, "ACallID") | ||
} |
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,206 @@ | ||
package slack | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"net/url" | ||
"strconv" | ||
) | ||
|
||
type Call struct { | ||
ID string `json:"id"` | ||
Title string `json:"title"` | ||
DateStart JSONTime `json:"date_start"` | ||
DateEnd JSONTime `json:"date_end"` | ||
ExternalUniqueID string `json:"external_unique_id"` | ||
JoinURL string `json:"join_url"` | ||
DesktopAppJoinURL string `json:"desktop_app_join_url"` | ||
ExternalDisplayID string `json:"external_display_id"` | ||
Users []CallUser `json:"users"` | ||
Channels []string `json:"channels"` | ||
} | ||
|
||
// A thin user representation which has a SlackID, ExternalID, or both. | ||
// | ||
// See: https://api.slack.com/apis/calls#users | ||
type CallUser struct { | ||
SlackID string `json:"slack_id,omitempty"` | ||
ExternalID string `json:"external_id,omitempty"` | ||
DisplayName string `json:"display_name,omitempty"` | ||
AvatarURL string `json:"avatar_url,omitempty"` | ||
} | ||
|
||
// Valid checks if the CallUser has a is valid with a SlackID or ExternalID or both. | ||
func (u CallUser) Valid() bool { | ||
return u.SlackID != "" || u.ExternalID != "" | ||
} | ||
|
||
type AddCallParameters struct { | ||
JoinURL string // Required | ||
ExternalUniqueID string // Required | ||
CreatedBy string // Required if using a bot token | ||
Title string | ||
DesktopAppJoinURL string | ||
ExternalDisplayID string | ||
DateStart JSONTime | ||
Users []CallUser | ||
} | ||
|
||
type UpdateCallParameters struct { | ||
Title string | ||
DesktopAppJoinURL string | ||
JoinURL string | ||
} | ||
|
||
type callResponse struct { | ||
Call Call `json:"call"` | ||
SlackResponse | ||
} | ||
|
||
// AddCall adds a new Call to the Slack API. | ||
func (api *Client) AddCall(params AddCallParameters) (Call, error) { | ||
return api.AddCallContext(context.Background(), params) | ||
} | ||
|
||
// AddCallContext adds a new Call to the Slack API. | ||
func (api *Client) AddCallContext(ctx context.Context, params AddCallParameters) (Call, error) { | ||
values := url.Values{ | ||
"token": {api.token}, | ||
"join_url": {params.JoinURL}, | ||
"external_unique_id": {params.ExternalUniqueID}, | ||
} | ||
if params.CreatedBy != "" { | ||
values.Set("created_by", params.CreatedBy) | ||
} | ||
if params.DateStart != 0 { | ||
values.Set("date_start", strconv.FormatInt(int64(params.DateStart), 10)) | ||
} | ||
if params.DesktopAppJoinURL != "" { | ||
values.Set("desktop_app_join_url", params.DesktopAppJoinURL) | ||
} | ||
if params.ExternalDisplayID != "" { | ||
values.Set("external_display_id", params.ExternalDisplayID) | ||
} | ||
if params.Title != "" { | ||
values.Set("title", params.Title) | ||
} | ||
if len(params.Users) > 0 { | ||
data, err := json.Marshal(params.Users) | ||
if err != nil { | ||
return Call{}, err | ||
} | ||
values.Set("users", string(data)) | ||
} | ||
|
||
response := &callResponse{} | ||
if err := api.postMethod(ctx, "calls.add", values, response); err != nil { | ||
return Call{}, err | ||
} | ||
|
||
return response.Call, response.Err() | ||
} | ||
|
||
// GetCallInfo returns information about a Call. | ||
func (api *Client) GetCall(callID string) (Call, error) { | ||
return api.GetCallContext(context.Background(), callID) | ||
} | ||
|
||
// GetCallInfoContext returns information about a Call. | ||
func (api *Client) GetCallContext(ctx context.Context, callID string) (Call, error) { | ||
values := url.Values{ | ||
"token": {api.token}, | ||
"id": {callID}, | ||
} | ||
|
||
response := &callResponse{} | ||
if err := api.postMethod(ctx, "calls.info", values, response); err != nil { | ||
return Call{}, err | ||
} | ||
return response.Call, response.Err() | ||
} | ||
|
||
func (api *Client) UpdateCall(callID string, params UpdateCallParameters) (Call, error) { | ||
return api.UpdateCallContext(context.Background(), callID, params) | ||
} | ||
|
||
// UpdateCallContext updates a Call with the given parameters. | ||
func (api *Client) UpdateCallContext(ctx context.Context, callID string, params UpdateCallParameters) (Call, error) { | ||
values := url.Values{ | ||
"token": {api.token}, | ||
"id": {callID}, | ||
} | ||
|
||
if params.DesktopAppJoinURL != "" { | ||
values.Set("desktop_app_join_url", params.DesktopAppJoinURL) | ||
} | ||
if params.JoinURL != "" { | ||
values.Set("join_url", params.JoinURL) | ||
} | ||
if params.Title != "" { | ||
values.Set("title", params.Title) | ||
} | ||
|
||
response := &callResponse{} | ||
if err := api.postMethod(ctx, "calls.update", values, response); err != nil { | ||
return Call{}, err | ||
} | ||
return response.Call, response.Err() | ||
} | ||
|
||
// EndCall ends a Call. | ||
func (api *Client) EndCall(callID string) error { | ||
return api.EndCallContext(context.Background(), callID) | ||
} | ||
|
||
// EndCallContext ends a Call. | ||
func (api *Client) EndCallContext(ctx context.Context, callID string) error { | ||
values := url.Values{ | ||
"token": {api.token}, | ||
"id": {callID}, | ||
} | ||
|
||
response := &SlackResponse{} | ||
if err := api.postMethod(ctx, "calls.end", values, response); err != nil { | ||
return err | ||
} | ||
return response.Err() | ||
} | ||
|
||
// CallAddUsers adds users to a Call. | ||
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. How would you feel about renaming these functions to use |
||
func (api *Client) CallAddUsers(callID string, users []CallUser) error { | ||
return api.CallAddUsersContext(context.Background(), callID, users) | ||
} | ||
|
||
// CallAddUsersContext adds users to a Call. | ||
func (api *Client) CallAddUsersContext(ctx context.Context, callID string, users []CallUser) error { | ||
return api.setCallUsers(ctx, "calls.participants.add", callID, users) | ||
} | ||
|
||
// CallRemoveUsers removes users from a Call. | ||
func (api *Client) CallRemoveUsers(callID string, users []CallUser) error { | ||
return api.CallRemoveUsersContext(context.Background(), callID, users) | ||
} | ||
|
||
// CallRemoveUsersContext removes users from a Call. | ||
func (api *Client) CallRemoveUsersContext(ctx context.Context, callID string, users []CallUser) error { | ||
return api.setCallUsers(ctx, "calls.participants.remove", callID, users) | ||
} | ||
|
||
func (api *Client) setCallUsers(ctx context.Context, method, callID string, users []CallUser) error { | ||
values := url.Values{ | ||
"token": {api.token}, | ||
"id": {callID}, | ||
} | ||
|
||
data, err := json.Marshal(users) | ||
if err != nil { | ||
return err | ||
} | ||
values.Set("users", string(data)) | ||
|
||
response := &SlackResponse{} | ||
if err := api.postMethod(ctx, method, values, response); err != nil { | ||
return err | ||
} | ||
return response.Err() | ||
} |
Oops, something went wrong.
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 you add the ability to pass the duration optional argument when ending the call?