Skip to content

Commit

Permalink
Implement a nameForHandle function
Browse files Browse the repository at this point in the history
  • Loading branch information
wtfaremyinitials committed Dec 22, 2017
1 parent 0640714 commit 4fa799d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
11 changes: 11 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,16 @@ function handleForName(name) {
})(name)
}

// Gets the display name for a given handle
// TODO: support group chats
function nameForHandle(handle) {
assert(typeof handle == 'string', 'handle must be a string')
return osa(handle => {
const Messages = Application('Messages')
return Messages.buddies.whose({ handle: handle }).name()[0]
})(handle)
}

// Sends a message to the given handle
function send(handle, message) {
assert(typeof handle == 'string', 'handle must be a string')
Expand Down Expand Up @@ -195,6 +205,7 @@ module.exports = {
send,
listen,
handleForName,
nameForHandle,
getRecentChats,
SUPPRESS_WARNINGS: false,
}
16 changes: 16 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,22 @@ Type: `Promise<string>`

A promise that resolves with the `handle` of the contact, or rejects if nobody was found.

### Get the name associated with a given handle

`nameForHandle(handle) -> Promise<name>`

**handle**

Type: `string`

The handle of a contact.

**return**

Type: `Promise<string>`

A promise that resolved with the full name of the desired contact, as displayed in `Messages.app`.

### Get recents chats

`getRecentChats(limit) -> Promise`
Expand Down

0 comments on commit 4fa799d

Please sign in to comment.