arooo icon indicating copy to clipboard operation
arooo copied to clipboard

Slack API integration

Open compwron opened this issue 6 years ago • 0 comments

Use the Slack API to

  • Revoke all old invites (admin presses button)
  • Re-send invites to current members who are not on slack (admin presses button)

https://github.com/kubernetes-sigs/slack-infra/blob/master/slack-moderator/users.go#L57-L74


func (h *handler) deactivateUser(interaction slackInteraction, targetUser string) error {
	result := struct {
		Ok    bool   `json:"ok"`
		Error string `json:"error,omitempty"`
	}{}

	resp, err := http.Post("https://slack.com/api/users.admin.setInactive", "application/x-www-form-urlencoded", bytes.NewBufferString("token="+h.adminToken+"&user="+targetUser))
	if err != nil {
		return fmt.Errorf("couldn't deactivate user %s: %v", targetUser, err)
	}
	if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
		return fmt.Errorf("failed to decode json: %v", err)
	}
	if !result.Ok {
		return fmt.Errorf("couldn't update membership: %s", result.Error)
	}

	return nil
}

compwron avatar Sep 05 '19 06:09 compwron