Closed hkboo closed 2 years ago
You can use channel = "@foo.bar"
to send a message to a specific user. To get a list of usernames, use slackr_users()
.
Who the message will be sent from depends on the type of token you have set up. If you're using a bot token (xoxb-...
), it'll send from the Slackbot
. If you're using a user token (xoxp-...
) it'll send from your username.
@mrkaye97 thank you for your answering. Now i knew using 'name' col ... not 'real_name' col ( that column' naming from slackr_users() )
When sending dm, Is there a way to use 'real_name' col instead of 'name' col?
No. You need to use name
or id
because that's what the API expects. If you want to use real_name
, you can do something like this:
library(dplyr)
get_name <- function(real_name) {
slackr_users() %>%
filter(real_name == !!real_name) %>%
pull(name) %>%
sprintf(
"@%s", .
)
}
slackr(
"Testing",
channel = get_name("Foo Bar")
)
Created on 2021-12-14 by the reprex package (v2.0.1)
How to use 'real_name' col? Check my codes T.T
library(dplyr)
slackr_users() %>%
filter(is_bot == FALSE) %>%
select(id, name, real_name)
id |
name |
real_name |
||
---|---|---|---|---|
USLACKBOT | slackbot | Slackbot | ||
U02QG6VJ678 | hkboo | Boo |
Is working!
slackr_msg(paste(my_msg, "to @hkboo using channel",Sys.time()), channel="@hkboo")
The slack API returned an error: channel_not_found
slackr_msg(paste(my_msg, "to @Boo using channel", Sys.time()), channel="@Boo")
You can use the code I pasted before:
library(dplyr)
get_name <- function(real_name) {
slackr_users() %>%
filter(real_name == !!real_name) %>%
pull(name) %>%
sprintf(
"@%s", .
)
}
slackr(
"Testing",
channel = get_name("Foo Bar")
)
Then get_name("Boo")
will return the <<name>>
, which you can then use as the channel.
Oh, I misunderstood as 'name' column is able to be entered directly into the parameter. Now I understand. Thank you!
Hello, i wonder slackr supports "A bot send user dm, not to channel?"