Skip to content

Update Slack Module #264

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

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ import (
"github.com/maddevsio/comedian/config"
"github.com/maddevsio/comedian/model"
"github.com/maddevsio/comedian/storage"
"github.com/nlopes/slack"
"github.com/nlopes/slack/slackevents"
log "github.com/sirupsen/logrus"
"github.com/slack-go/slack"
"github.com/slack-go/slack/slackevents"
)

// ComedianAPI struct used to handle slack requests (slash commands)
Expand Down Expand Up @@ -190,7 +190,7 @@ func (api *ComedianAPI) login(c echo.Context) error {
return echo.NewHTTPError(http.StatusBadRequest, incorrectDataFormat)
}

resp, err := slack.GetOAuthResponse(api.config.SlackClientID, api.config.SlackClientSecret, logingPayload.Code, logingPayload.RedirectURI, false)
resp, err := slack.GetOAuthV2Response(&http.Client{}, api.config.SlackClientID, api.config.SlackClientSecret, logingPayload.Code, logingPayload.RedirectURI)
if err != nil {
log.Errorf("GetOAuthResponse failed: %v", err)
return echo.NewHTTPError(http.StatusBadRequest, err.Error())
Expand Down Expand Up @@ -491,24 +491,24 @@ func (api *ComedianAPI) auth(c echo.Context) error {

code := urlValues.Get("code")

resp, err := slack.GetOAuthResponse(api.config.SlackClientID, api.config.SlackClientSecret, code, "", false)
resp, err := slack.GetOAuthV2Response(&http.Client{}, api.config.SlackClientID, api.config.SlackClientSecret, code, "")
if err != nil {
log.WithFields(log.Fields(map[string]interface{}{"config": api.config, "urlValues": urlValues, "error": err})).Error("auth failed on GetOAuthResponse")
return err
}

workspaceSettings, err := api.db.GetWorkspaceByWorkspaceID(resp.TeamID)
workspaceSettings, err := api.db.GetWorkspaceByWorkspaceID(resp.Team.ID)
if err != nil {
cp, err := api.db.CreateWorkspace(model.Workspace{
CreatedAt: time.Now().Unix(),
BotUserID: resp.Bot.BotUserID,
BotUserID: resp.BotUserID,
NotifierInterval: 30,
Language: "en",
MaxReminders: 3,
ReminderOffset: 10,
BotAccessToken: resp.Bot.BotAccessToken,
WorkspaceID: resp.TeamID,
WorkspaceName: resp.TeamName,
BotAccessToken: resp.AccessToken,
WorkspaceID: resp.Team.ID,
WorkspaceName: resp.Team.Name,
ReportingChannel: "",
ReportingTime: "10am",
ProjectsReportsEnabled: false,
Expand All @@ -528,16 +528,16 @@ func (api *ComedianAPI) auth(c echo.Context) error {
return c.Redirect(http.StatusMovedPermanently, api.config.UIurl)
}

workspaceSettings.BotAccessToken = resp.Bot.BotAccessToken
workspaceSettings.BotUserID = resp.Bot.BotUserID
workspaceSettings.BotAccessToken = resp.AccessToken
workspaceSettings.BotUserID = resp.BotUserID

settings, err := api.db.UpdateWorkspace(workspaceSettings)
if err != nil {
log.WithFields(log.Fields(map[string]interface{}{"resp": resp, "error": err})).Error("auth failed on CreateBotSettings")
return err
}

bot, err := api.SelectBot(resp.TeamID)
bot, err := api.SelectBot(resp.Team.ID)
if err != nil {
log.Error(err)
return err
Expand Down
4 changes: 2 additions & 2 deletions botuser/botuser.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/maddevsio/comedian/model"
"github.com/maddevsio/comedian/storage"
"github.com/nicksnyder/go-i18n/v2/i18n"
"github.com/nlopes/slack"
"github.com/slack-go/slack"
log "github.com/sirupsen/logrus"
)

Expand Down Expand Up @@ -345,7 +345,7 @@ func (bot *Bot) analizeStandup(message string) string {

// SendMessage posts a message in a specified channel visible for everyone
func (bot *Bot) SendMessage(channel, message string, attachments []slack.Attachment) error {
_, _, err := bot.slack.PostMessage(channel, message, slack.PostMessageParameters{Attachments: attachments})
_, _, err := bot.slack.PostMessage(channel, slack.MsgOptionText(message,true), slack.MsgOptionAttachments(attachments...))
return err
}

Expand Down
2 changes: 1 addition & 1 deletion botuser/deadlines.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"time"

"github.com/nicksnyder/go-i18n/v2/i18n"
"github.com/nlopes/slack"
"github.com/slack-go/slack"
"github.com/olebedev/when"
"github.com/olebedev/when/rules/en"
"github.com/olebedev/when/rules/ru"
Expand Down
2 changes: 1 addition & 1 deletion botuser/deadlines_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package botuser
import (
"testing"

"github.com/nlopes/slack"
"github.com/slack-go/slack"
"github.com/stretchr/testify/assert"
)

Expand Down
2 changes: 1 addition & 1 deletion botuser/onbording_message.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package botuser

import (
"github.com/nicksnyder/go-i18n/v2/i18n"
"github.com/nlopes/slack"
log "github.com/sirupsen/logrus"
"github.com/slack-go/slack"
)

func (bot *Bot) modifyOnbordingMessage(command slack.SlashCommand) string {
Expand Down
2 changes: 1 addition & 1 deletion botuser/reporting.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

"github.com/maddevsio/comedian/model"
"github.com/nicksnyder/go-i18n/v2/i18n"
"github.com/nlopes/slack"
"github.com/slack-go/slack"
"github.com/olebedev/when"
"github.com/olebedev/when/rules/en"
"github.com/olebedev/when/rules/ru"
Expand Down
2 changes: 1 addition & 1 deletion botuser/standupers.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (

"github.com/maddevsio/comedian/model"
"github.com/nicksnyder/go-i18n/v2/i18n"
"github.com/nlopes/slack"
log "github.com/sirupsen/logrus"
"github.com/slack-go/slack"
)

func (bot *Bot) joinCommand(command slack.SlashCommand) string {
Expand Down
2 changes: 1 addition & 1 deletion botuser/standupers_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package botuser

import (
"github.com/nlopes/slack"
"github.com/slack-go/slack"
"github.com/stretchr/testify/assert"
"testing"
)
Expand Down
2 changes: 1 addition & 1 deletion botuser/submittion_days.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package botuser

import (
"github.com/nicksnyder/go-i18n/v2/i18n"
"github.com/nlopes/slack"
log "github.com/sirupsen/logrus"
"github.com/slack-go/slack"
)

func (bot *Bot) modifySubmittionDays(command slack.SlashCommand) string {
Expand Down
2 changes: 1 addition & 1 deletion botuser/tz.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"time"

"github.com/nicksnyder/go-i18n/v2/i18n"
"github.com/nlopes/slack"
log "github.com/sirupsen/logrus"
"github.com/slack-go/slack"
)

func (bot *Bot) modifyTZ(command slack.SlashCommand) string {
Expand Down
2 changes: 1 addition & 1 deletion model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"strings"
"time"

"github.com/nlopes/slack"
"github.com/slack-go/slack"
)

// Standup model used for serialization/deserialization stored standups
Expand Down