Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions src/slack
Original file line number Diff line number Diff line change
Expand Up @@ -252,13 +252,23 @@ function jqify() {

function lchannel() {
case "${channel}" in
*@*)
local _user=$(\
curl -s -X POST https://slack.com/api/users.lookupByEmail --data-urlencode "token=${token}" --data-urlencode "email=${channel}" 2>&1 | \
jq -r ".user.id")
local _channel=$(\
curl -s -X POST https://slack.com/api/im.open --data-urlencode "token=${token}" --data-urlencode "user=${_user}" 2>&1 | \
jq -r ".channel.id")

echo ${_channel}
;;
@*)
local _user=$(\
curl -s -X POST https://slack.com/api/users.list --data-urlencode "token=${token}" 2>&1 | \
jq -r ".members | map(select(.name == \"${channel/@/}\" or .profile.display_name == \"${channel/@/}\")) | .[0].id")
local _channel=$(\
curl -s -X POST https://slack.com/api/im.list --data-urlencode "token=${token}" 2>&1 | \
jq -r ".ims | map(select(.user == \"${_user}\")) | .[].id")
curl -s -X POST https://slack.com/api/im.open --data-urlencode "token=${token}" --data-urlencode "user=${_user}" 2>&1 | \
jq -r ".channel.id")

echo ${_channel}
;;
Expand All @@ -268,6 +278,13 @@ function lchannel() {

function luser() {
case "${user}" in
*@*)
local _user=$(\
curl -s -X POST https://slack.com/api/users.lookupByEmail --data-urlencode "token=${token}" --data-urlencode "email=${user}" 2>&1 | \
jq -r ".user.id")

echo ${_user}
;;
@*)
local _user=$(\
curl -s -X POST https://slack.com/api/users.list --data-urlencode "token=${token}" 2>&1 | \
Expand Down
4 changes: 4 additions & 0 deletions test/integration/chat.bats
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ load suite
build/bin/slack chat send 'chat send to direct channel should succeed' @rockymadden
}

@test 'chat send to direct channel via email should succeed' {
build/bin/slack chat send 'chat send to direct channel via email should succeed' github@rockymadden.com
}

@test 'chat send to invalid channel should fail' {
run build/bin/slack chat send 'chat send to invalid channel should fail' '#invalid'
[ ${status} -eq 1 ]
Expand Down