diff --git a/asana.go b/asana.go index 4e20e02..f3ef681 100644 --- a/asana.go +++ b/asana.go @@ -23,6 +23,7 @@ type addTaskRequest struct { type addTaskRequestInt struct { Name string `json:"name"` + HtmlNotes string `json:"html_notes"` Workspace string `json:"workspace"` Assignee string `json:"assignee"` Projects []string `json:"projects"` @@ -38,10 +39,11 @@ func NewAsanaClient() *AsanaClient { } } -func (ac *AsanaClient) CreateTask(name string) error { +func (ac *AsanaClient) CreateTask(name string, notes string) error { body := &addTaskRequest{ Data: &addTaskRequestInt{ Name: name, + HtmlNotes: notes, Workspace: ac.workspace, Assignee: ac.assignee, Projects: []string{ac.project}, diff --git a/slack.go b/slack.go index c914a56..deb6958 100644 --- a/slack.go +++ b/slack.go @@ -231,9 +231,22 @@ func (sc *SlackClient) GetTitle(item *Item, user *User, channel *Channel) (strin case channel.IsIm: return fmt.Sprintf("[%s] %s", user.Name, item.Message.Text), nil case channel.IsMpIm: - return fmt.Sprintf("[%s -> %s] %s", user.Name, sc.getTaggedNamesString(channel.Purpose.Value), item.Message.Text), nil + return fmt.Sprintf("[%s] %s", user.Name, item.Message.Text), nil case channel.IsChannel: - return fmt.Sprintf("[%s -> #%s] %s", user.Name, channel.Name, item.Message.Text), nil + return fmt.Sprintf("[%s] %s", user.Name, item.Message.Text), nil + default: + return "", fmt.Errorf("unknown channel type: %#v", channel) + } +} + +func (sc *SlackClient) GetNotes(item *Item, user *User, channel *Channel) (string, error) { + switch { + case channel.IsIm: + return "", nil + case channel.IsMpIm: + return fmt.Sprintf("In %s", sc.getTaggedNamesString(channel.Purpose.Value)), nil + case channel.IsChannel: + return fmt.Sprintf("In #%s", channel.Name), nil default: return "", fmt.Errorf("unknown channel type: %#v", channel) } diff --git a/slack2asana.go b/slack2asana.go index b454ffe..c249b5d 100644 --- a/slack2asana.go +++ b/slack2asana.go @@ -20,7 +20,10 @@ func main() { for { time.Sleep(time.Duration(rand.Intn(60)) * time.Second) - Poll(ac, sc) + err = Poll(ac, sc) + if err != nil { + log.Printf("%s", err) + } } } @@ -50,9 +53,14 @@ func Poll(ac *AsanaClient, sc *SlackClient) error { return err } + notes, err := sc.GetNotes(item, user, channel) + if err != nil { + return err + } + log.Printf("%s\n", title) - err = ac.CreateTask(title) + err = ac.CreateTask(title, notes) if err != nil { return err }