Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
RocketChat
Rocket.Chat.js.SDK
Commits
11cb6b1f
Commit
11cb6b1f
authored
Mar 06, 2018
by
Tim Kinnane
Browse files
fix(roomid): Get direct message room ID from attribute
parent
1aeabf0f
Changes
2
Expand all
Hide whitespace changes
Inline
Side-by-side
package-lock.json
0 → 100644
View file @
11cb6b1f
This diff is collapsed.
Click to expand it.
src/lib/driver.ts
View file @
11cb6b1f
...
...
@@ -344,9 +344,10 @@ export function getRoomName (id: string): Promise<string> {
/**
* Get ID for a DM room by its recipient's name.
* Will create a DM (with the bot) if it doesn't exist already.
* @todo test why create resolves with object instead of simply ID
*/
export
function
getDirectMessageRoomId
(
username
:
string
):
Promise
<
string
>
{
return
cacheCall
(
'
createDirectMessage
'
,
username
)
return
cacheCall
(
'
createDirectMessage
'
,
username
)
.
then
((
DM
)
=>
DM
.
rid
)
}
/** Join the bot into a room by its name or ID */
...
...
@@ -377,7 +378,7 @@ export function prepareMessage (content: string | IMessage, roomId?: string): Me
export
function
sendMessageByRoomId
(
content
:
string
|
string
[]
|
IMessage
,
roomId
:
string
):
Promise
<
any
>
{
let
messages
:
Message
[]
=
[]
if
(
Array
.
isArray
(
content
))
{
content
.
forEach
((
msg
)
=>
messages
.
push
(
prepareMessage
(
msg
,
roomId
)))
content
.
forEach
((
text
)
=>
messages
.
push
(
prepareMessage
(
text
,
roomId
)))
}
else
{
messages
.
push
(
prepareMessage
(
content
))
}
...
...
@@ -393,6 +394,13 @@ export function sendMessageByRoom (content: string | string[] | IMessage, room:
return
getRoomId
(
room
).
then
((
roomId
)
=>
sendMessageByRoomId
(
content
,
roomId
))
}
/**
* Send a message to a user in a DM.
*/
export
function
sendDirectToUser
(
message
:
string
|
string
[]
|
IMessage
,
username
:
string
):
Promise
<
any
>
{
return
getDirectMessageRoomId
(
username
).
then
((
rid
)
=>
sendMessageByRoomId
(
message
,
rid
))
}
/**
* Send a prepared message object (with pre-defined room ID).
* Usually prepared and called by sendMessageByRoomId or sendMessageByRoom.
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment