Move channel name to notes

This commit is contained in:
Ian Gulliver
2022-10-28 16:10:04 +00:00
parent 7bd2d90a20
commit 3c96973678
3 changed files with 28 additions and 5 deletions

View File

@@ -23,6 +23,7 @@ type addTaskRequest struct {
type addTaskRequestInt struct { type addTaskRequestInt struct {
Name string `json:"name"` Name string `json:"name"`
HtmlNotes string `json:"html_notes"`
Workspace string `json:"workspace"` Workspace string `json:"workspace"`
Assignee string `json:"assignee"` Assignee string `json:"assignee"`
Projects []string `json:"projects"` 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{ body := &addTaskRequest{
Data: &addTaskRequestInt{ Data: &addTaskRequestInt{
Name: name, Name: name,
HtmlNotes: notes,
Workspace: ac.workspace, Workspace: ac.workspace,
Assignee: ac.assignee, Assignee: ac.assignee,
Projects: []string{ac.project}, Projects: []string{ac.project},

View File

@@ -231,9 +231,22 @@ func (sc *SlackClient) GetTitle(item *Item, user *User, channel *Channel) (strin
case channel.IsIm: case channel.IsIm:
return fmt.Sprintf("[%s] %s", user.Name, item.Message.Text), nil return fmt.Sprintf("[%s] %s", user.Name, item.Message.Text), nil
case channel.IsMpIm: 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: 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("<body>In %s</body>", sc.getTaggedNamesString(channel.Purpose.Value)), nil
case channel.IsChannel:
return fmt.Sprintf("<body>In #%s</body>", channel.Name), nil
default: default:
return "", fmt.Errorf("unknown channel type: %#v", channel) return "", fmt.Errorf("unknown channel type: %#v", channel)
} }

View File

@@ -20,7 +20,10 @@ func main() {
for { for {
time.Sleep(time.Duration(rand.Intn(60)) * time.Second) 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 return err
} }
notes, err := sc.GetNotes(item, user, channel)
if err != nil {
return err
}
log.Printf("%s\n", title) log.Printf("%s\n", title)
err = ac.CreateTask(title) err = ac.CreateTask(title, notes)
if err != nil { if err != nil {
return err return err
} }