Skip to content
This repository has been archived by the owner on Jul 9, 2022. It is now read-only.

Commit

Permalink
fixes to setReaction
Browse files Browse the repository at this point in the history
change `addReaction` to `setReaction` in error message
place docs to setReaction in alphabetical order
make table with emojis
remove some trailing spaces
  • Loading branch information
ravkr committed Mar 30, 2017
1 parent 5676a33 commit b1a42ea
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 33 deletions.
51 changes: 26 additions & 25 deletions DOCS.md
Expand Up @@ -30,8 +30,8 @@
* [`api.searchForThread`](#searchForThread)
* [`api.sendMessage`](#sendMessage)
* [`api.sendTypingIndicator`](#sendTypingIndicator)
* [`api.setOptions`](#setOptions)
* [`api.setMessageReaction`](#setMessageReaction)
* [`api.setOptions`](#setOptions)
* [`api.setTitle`](#setTitle)

---------------------------------------
Expand Down Expand Up @@ -887,6 +887,31 @@ __Arguments__
---------------------------------------
<a name="setMessageReaction"></a>
### api.setMessageReaction(reaction, messageID[, callback])
Sets reaction on message
__Arguments__
* `reaction`: A string containing either an emoji, an emoji in unicode, or an emoji shortcut (see list of supported emojis below). The string can be left empty ("") in order to remove a reaction.
* `messageID`: A string representing the message ID.
* `callback(err)` - A callback called when sending the reaction is done.
__Supported Emojis__
|Emoji|Text|Unicode|Shortcuts|
|---|---|---|---|
|😍|`😍`|`\uD83D\uDE0D`|`:love:`, `:heart_eyes:`|
|😆|`😆`|`\uD83D\uDE06`|`:haha:`, `:laughing:`|
|😮|`😮`|`\uD83D\uDE2E`|`:wow:`, `:open_mouth:`|
|😢|`😢`|`\uD83D\uDE22`|`:sad:`, `:cry:`|
|😠|`😠`|`\uD83D\uDE20`|`:angry:`|
|👍|`👍`|`\uD83D\uDC4D`|`:like:`, `:thumbsup:`|
|👎|`👎`|`\uD83D\uDC4E`|`:dislike:`, `:thumbsdown:`|
---------------------------------------
<a name="setOptions"></a>
### api.setOptions(options)
Expand Down Expand Up @@ -934,30 +959,6 @@ login({appState: JSON.parse(fs.readFileSync('appstate.json', 'utf8'))}, (err, ap
});
```
---------------------------------------
<a name="setMessageReaction"></a>
### api.setMessageReaction(reaction, messageID[, callback])
Sets reaction on message
__Arguments__
* `reaction`: A string contains `emoji`, `emoji shortcut`, `emoji in unicode` or left `empty string` for delete reaction (look down for list of supported emojis)
* `messageID`: A string representing the message ID.
* `callback(err)` - A callback called when sending the reaction is done.
__Supported Emojis__
* 😍 - Unicode: `\uD83D\uDE0D`, Shortcut: `:heart_eyes:` or `:love:`
* 😆 - Unicode: `\uD83D\uDE06`, Shortcut: `:laughing:` or `:haha:`
* 😮 - Unicode: `\uD83D\uDE2E`, Shortcut: `:open_mouth:` or `:wow:`
* 😢 - Unicode: `\uD83D\uDE22`, Shortcut: `:cry:` or `:sad:`
* 😠 - Unicode: `\uD83D\uDE20`, Shortcut: `:angry:`
* 👍 - Unicode: `\uD83D\uDC4D`, Shortcut: `:thumbsup:` or `:like:`
* 👎 - Unicode: `\uD83D\uDC4E`, Shortcut: `:thumbsdown:` or `:dislike:`
---------------------------------------
<a name="setTitle"></a>
Expand Down
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -70,14 +70,14 @@ Result:
* [`api.searchForThread`](DOCS.md#searchForThread)
* [`api.sendMessage`](DOCS.md#sendMessage)
* [`api.sendTypingIndicator`](DOCS.md#sendTypingIndicator)
* [`api.setOptions`](DOCS.md#setOptions)
* [`api.setMessageReaction`](DOCS.md#setMessageReaction)
* [`api.setOptions`](DOCS.md#setOptions)
* [`api.setTitle`](DOCS.md#setTitle)

## Main Functionality

### Sending a message
#### api.sendMessage(message, threadID, [callback])
#### api.sendMessage(message, threadID[, callback])

Various types of message can be sent:
* *Regular:* set field `body` to the desired message as a string.
Expand Down
12 changes: 6 additions & 6 deletions src/setMessageReaction.js
Expand Up @@ -8,7 +8,7 @@ module.exports = function(defaultFuncs, api, ctx) {
if(!callback) {
callback = function() {};
}

switch (reaction) {
case "\uD83D\uDE0D": //:heart_eyes:
case "\uD83D\uDE06": //:laughing:
Expand Down Expand Up @@ -51,17 +51,17 @@ module.exports = function(defaultFuncs, api, ctx) {
return callback({error: "Reaction is not a valid emoji."});
break;
}

var variables = {
data: {
client_mutation_id: ctx.clientMutationId++,
actor_id: ctx.userID,
action: reaction == "" ? "REMOVE_REACTION" : "ADD_REACTION",
message_id: messageID,
reaction: reaction
reaction: reaction
}
};

var qs = {
doc_id: "1491398900900362",
variables: JSON.stringify(variables),
Expand All @@ -73,15 +73,15 @@ module.exports = function(defaultFuncs, api, ctx) {
.then(utils.parseAndCheckLogin(ctx.jar, defaultFuncs))
.then(function(resData) {
if (!resData) {
throw {error: "addReaction returned empty object."};
throw {error: "setReaction returned empty object."};
}
if(resData.error) {
throw resData;
}
callback(null);
})
.catch(function(err) {
log.error("addReaction", err);
log.error("setReaction", err);
return callback(err);
});
};
Expand Down

0 comments on commit b1a42ea

Please sign in to comment.