I am trying to make a bot that add the engineer on duty to a group. I almost have everything working but it's failing on the final step.
Keep in mind I just learned about js/nodejs 3-4 days ago and I am not a developer. So be gentle.
x in one of the [ ])x in each of the [ ])The problem is that the usergroups.users.update() returns
error: Response not OK: invalid_array_arg
Unhandled rejection Error: invalid_array_arg
hubot-slack version: 4.5.4
node version: 10.0.0
OS version(s): macosx sierra
I use the following code when this issue happens.
web = new WebClient(process.env.SLACK_OAUTH_TOKEN)
web.usergroups.list()
.then(usergroups_result => {
for (let k in usergroups_result.usergroups) {
const userGroupName = usergroups_result.usergroups[k].name
if (userGroupName != null && userGroupName.toLowerCase() === slackUserGroup) {
var userGroup = usergroups_result.usergroups[k]
}
}
web.usergroups.users.update({
usergroup: userGroup.team_id,
users: user.id,
})
})
.catch(err => res.reply('can\'t deal with this one: ' + err))
So I am first going through the usergroups to find it by name. Since not everyone knows their groupId by heart. This results in only 1 group (I checked).
I have a different function that grabs the user and I checked the contents of user.id and its only 1 id of the slack user as a string.
I tried to add the users like so: [user.id].join(",") but this didn't matter.
Response.ok
error: Response not OK: invalid_array_arg
Unhandled rejection Error: invalid_array_arg
Anyone knows that I am doing wrong? thnx!
@Plork first of all, you're already off to a great start, esp considering you've only got a few weeks experience! congrats on making the leap 馃帀
i think i see two things that are incorrect. the first is pretty simple. when you call usergroups.users.update, the usergroup argument should be set to userGroup.id (not team_id). the second thing is based on something you said: "I am trying to make a bot that add the engineer on duty to a group." if you really want to add a user, then you need to include all the existing users in the users argument, otherwise you'd overwrite the list and remove the existing users. in other words, the docs describe the users argument with:
A comma separated string of encoded user IDs that represent the entire list of users for the User Group.
so we need the whole list of users in that user group _appended with_ the user you wish to add. we can get the list by calling usergroups.users.list. you can append the user ID and flatten it out to a comma-separated list like so: userList.append(user.id).join(',').
let us know if you have any more questions and good luck!
well actually I want to overwrite the existing users so that's correct. ;) But the team_id > id I will fix.
I want the cust to be able to reach the engineer on duty with @eod or something without having to ask who is the engineer.
oh lol sorry @EoD forgot get add quotes around it was meant to mimic a slack group, never thought it could have been someone's username ;)
but I am still getting the error:
error: Response not OK: invalid_array_arg
after changing team_id to id
btw @aoberoi thnx for the help i got it working!