Skip to content
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

[Patch] Added call block #897

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions block.go
Expand Up @@ -17,6 +17,7 @@ const (
MBTFile MessageBlockType = "file"
MBTInput MessageBlockType = "input"
MBTHeader MessageBlockType = "header"
MBTCall MessageBlockType = "call"
)

// Block defines an interface all block types should implement
Expand Down
70 changes: 70 additions & 0 deletions block_call.go
@@ -0,0 +1,70 @@
package slack

// CallBlock defines data that is used to display call fields.
//
// More Information: https://api.slack.com/reference/block-kit/blocks#call
type CallBlock struct {
Type MessageBlockType `json:"type"`
BlockID string `json:"block_id,omitempty"`
CallID string `json:"call_id,omitempty"`
Call CallObject `json:"call,omitempty"`
APIDecorationAvailable bool `json:"api_decoration_available,omitempty"`
}

// CallObject declares the interface for call blocks.
type CallObject interface{}

// MessageBlockType defines a named string type to define each media backend type
// as a constant for use within the package.
type MediaBackendType string

const (
MBETPlatformCall MediaBackendType = "platform_call"
)

type ZoomCall struct {
CallObject
MediaBackendType MediaBackendType `json:"media_backend_type"`
Info ZoomCallInfo `json:"v1,omitempty"`
}

type ZoomCallInfo struct {
AppId string `json:"app_id"`
ActiveParticipants []*CallParticipant `json:"active_participants"`
AllParticipants []*CallParticipant `json:"all_participants"`
Channels []string `json:"channels"`
CreatedBy string `json:"created_by"`
DateEnd uint64 `json:"date_end"`
DateStart uint64 `json:"date_start"`
DesktopAppJoinUrl string `json:"desktop_app_join_url"`
DisplayId string `json:"display_id"`
HasEnded bool `json:"has_ended"`
Id string `json:"id"`
IsDmCall bool `json:"is_dm_call"`
JoinUrl string `json:"join_url"`
Name string `json:"name"`
WasAccepted bool `json:"was_accepted"`
WasMissed bool `json:"was_missed"`
WasRejected bool `json:"was_rejected"`
}

type CallParticipant struct {
ID string `json:"external_id"`
AvatarUrl string `json:"avatar_url,omitempty"`
DisplayName string `json:"display_name,omitempty"`
}

// BlockType returns the type of the block
func (s CallBlock) BlockType() MessageBlockType {
return s.Type
}

// NewCallBlock returns a new instance of an input block
func NewCallBlock(blockID, callID string, call CallObject) *CallBlock {
return &CallBlock{
Type: MBTCall,
BlockID: blockID,
CallID: callID,
Call: call,
}
}
42 changes: 42 additions & 0 deletions block_call_test.go
@@ -0,0 +1,42 @@
package slack

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestNewCallBlock(t *testing.T) {

call := &ZoomCall{
MediaBackendType: MBETPlatformCall,
Info: ZoomCallInfo{
ActiveParticipants: []*CallParticipant{},
AllParticipants: []*CallParticipant{
&CallParticipant{
ID: "KArkyRIMNvAuHA-hxSsoPg",
AvatarUrl: "",
DisplayName: "Adam Savage",
},
},
AppId: "A5GE9BMQC",
Channels: []string{"FU1NC8HAN"},
CreatedBy: "U0106V8C3DM",
DateEnd: 0,
DateStart: 1613383918,
DesktopAppJoinUrl: "zoommtg://zoom.us/join?action=join\u0026confno=9097887221\u0026pwd=Y1MzaVl3QlArYnhvWnlqdEtqUlE1UT09\u0026confid=dXNzPWdfTm1CNkhWd1BDaXVYX1lmUG51RTk0eVFBd3NMNFVSUDBmMjBBMlJyLWdrVGRJNXlMQnFCeGJCV0V1eWlIRHZYY1FUbEF4N2p4NzM0YldsV2VuWFpNNVp3S1UueWtsQWRCMmdfSWtpQzhUcA%3D%3D\u0026t=1613383917995",
DisplayId: "909-7887-221",
HasEnded: false,
Id: "M01MA5CBOOK",
IsDmCall: false,
JoinUrl: "https://zoom.us/j/9097887221?pwd=Y1MzaVl3QlArYnhvWnlqdEtqUlE1UT09",
Name: "Zoom meeting started by Adam Savage",
WasAccepted: false,
WasMissed: false,
WasRejected: false,
},
}
callBlock := NewCallBlock("8JP", "R01MX5MCBQE", call)
assert.Equal(t, string(callBlock.Type), "call")

}
2 changes: 2 additions & 0 deletions block_conv.go
Expand Up @@ -67,6 +67,8 @@ func (b *Blocks) UnmarshalJSON(data []byte) error {
block = &InputBlock{}
case "section":
block = &SectionBlock{}
case "call":
block = &CallBlock{}
default:
block = &UnknownBlock{}
}
Expand Down