Git Product home page Git Product logo

mattermost-client's Introduction

Mattermost-client

Build Status

Mattermost client which uses the Web API and websockets.

Features

The client was primarily written for use by the Matteruser Hubot adapter. The initial implementation thus contains only the minimal set of API calls to support this. Pull requests to expand API support are very welcome!

Highlights

  • Logs into Mattermost team server with username and password ..OR..
  • Uses a personal access token for authentication
  • Connects via websocket for real-time interaction
  • Can post messages to joined channels
  • Can be invited to channels / DMs since its just a regular user
  • Initiate DMs to users
  • Splits large messages in 4K chunks

Environment variables

The following environment variables may be defined to alter behavior:

Variable Required Description
MATTERMOST_TLS_VERIFY No (default: true) set to 'false' to allow connections when certs can not be verified (ex: self-signed, internal CA, ... - MITM risks)
MATTERMOST_LOG_LEVEL No (default: info) set log level (also: debug, ...)
MATTERMOST_USE_TLS No (default: true) set to 'false' to use http/ws instead of https/wss

Mattermost 5.x.x

This client always tries to track the latest version of Mattermost. As of version 5.0.0 of Mattermost might introduce backwards incompatible API changes make sure you are using the latest version of this library.

Older versions of Mattermost

For interaction with Mattermost versions please use version of the library matching the Mattermost version.

TODO

  • Implement more API calls

License

The code is licensed under MIT.

mattermost-client's People

Contributors

3ch01c avatar ahmetcetin avatar alexiri avatar benjamin-loison avatar contolini avatar danielruf avatar dependabot-preview[bot] avatar dependabot[bot] avatar elephanter avatar hagenmorano avatar hesstobi avatar hp41 avatar judokus avatar jwernicke avatar kongr45gpen avatar learnin avatar lizulana avatar loafoe avatar marthym avatar mlmnetcologne avatar mxiamxia avatar snyk-bot avatar stonyz avatar tomer953 avatar trentm avatar vhex avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

mattermost-client's Issues

Slack attachments are broken

It appears that this commit 16ce139 broke slack attachments. Slack attachments do not have a message variable, which causes this to throw

TypeError: Cannot read property 'match' of undefined
  at Client._chunkMessage (/Users/horwitz/Sites/ghostbot/node_modules/hubot-matteruser/node_modules/mattermost-client/src/client.coffee:290:21)
  at Client.customMessage (/Users/horwitz/Sites/ghostbot/node_modules/hubot-matteruser/node_modules/mattermost-client/src/client.coffee:262:19)
  at Matteruser.slackAttachmentMessage (/Users/horwitz/Sites/ghostbot/node_modules/hubot-matteruser/src/matteruser.coffee:226:17)
  at EventEmitter.<anonymous> (/Users/horwitz/Sites/ghostbot/node_modules/hubot-matteruser/src/matteruser.coffee:1:1)

Allow adding headers and add X-Requested-With

_apiCall(method, path, params, callback, callback_params) {
let isForm = false;
if (typeof method !== 'string') {
isForm = true;
method = method.method;
}
if (callback_params == null) { callback_params = {}; }
let post_data = '';
if (params != null) { post_data = JSON.stringify(params); }
const options = {
uri: (useTLS ? 'https://' : 'http://') + this.host + ((this.options.httpPort != null) ? `:${this.options.httpPort}` : "") + apiPrefix + path,
method,
json: params,
rejectUnauthorized: tlsverify,
headers: {
'Content-Type': 'application/json',
'Content-Length': new TextEncoder.TextEncoder('utf-8').encode(post_data).length

To be able to receive the set-cookie (MMAUTHTOKEN, MMUSERID, MMCSRF) headers, add 'X-Requested-With': 'XMLHttpRequest' to headers in options in _apiCall.

Suggestion: Add headers option to options like

{
   wssPort: 443, 
   httpPort: 80, 
   headers: {'X-Requested-With': 'XMLHttpRequest', 'date': '123', [...]} 
}

and merge with existing headers like Object.assign({}, existingHeaders, this.options.headers)

feature request: gitlab login

It appears we can't log in using gitlab, only straight username + password.

If you know any client that can get into Mattermost using a gitlab authentication token(?), I'd be happy to try to set it up, but I'm a bit of a noob and this is the first Mattermost client I've dealt with, and my searches haven't turned up anything.

Mattermost moving to API version 4

Hey @loafoe!

First, hugely appreciate you sharing this project back with the world. Fantastic work!

I wanted to let you know about our plans moving to API v4:

To make the Mattermost API web service easier to use and to offer more powerful options for these integrations, Mattermost will be moving to a new API version soon. Highlights include:

  • Fully documented API endpoints
  • More in-depth access to server functionality
  • Wider use of established HTTP verbs
  • Consistent endpoint structures
  • A new and improved Go driver

We plan to release API version 4 on March 16th, with Mattermost server 3.7. While the current API version 3 will be supported until September 16th, we recommend you begin using API version 4 soon after its release.

Contributing

API version 4 is an active and on-going project. If you're interested in helping contribute, please join our Mattermost community instance and the APIv4 channel.

We've prepared a contribution process for APIv4 and a progress tracker for new APIv4 enpoints to help you get started.

We're also open for suggestions on adding new API endpoints to help with your integration.

mattermost client not proxy aware.

Unfortunately the mattermost client is not proxy aware. This leads to the effect, that everything within mattermost client, which is based on HTTPS request (so i.e. everything within function "_apiCall") will be perfectly routed through a proxy, if the corresponding environment variables are set.

But the calls in "connect: ->" are based on WebSocket, which are not proxy-aware. So if you wireshark the connection, you see all request through the proxy and the Websocket calls are tried directly.

Error when getting the channels

Hi,

Firstly, thanks for the awesome matteruser adapter! I'm trying to switch from hubot-mattermost to your adapter. Unfortunately when I load hubot with the adapter I see the following error:

[Tue May 31 2016 22:32:01 GMT+0530 (IST)] INFO Logging in...
[Tue May 31 2016 22:32:02 GMT+0530 (IST)] INFO Websocket URL: wss://mattermost.mo.sap.corp:443/api/v3/users/websocket
[Tue May 31 2016 22:32:02 GMT+0530 (IST)] INFO Logged in as user "jarvis" but not connected yet.
[Tue May 31 2016 22:32:02 GMT+0530 (IST)] INFO Connecting...
[Tue May 31 2016 22:32:02 GMT+0530 (IST)] ERROR TypeError: Cannot convert undefined or null to object
at Client._onChannels (/home/i055636/git/alfred/node_modules/mattermost-client/src/client.coffee:95:13, :141:45)
at /home/i055636/git/alfred/node_modules/mattermost-client/src/client.coffee:1:1, :3:61
at IncomingMessage. (/home/i055636/git/alfred/node_modules/mattermost-client/src/client.coffee:316:25, :427:22)
at emitNone (events.js:91:20)
at IncomingMessage.emit (events.js:185:7)
at endReadableNT (_stream_readable.js:926:12)
at _combinedTickCallback (internal/process/next_tick.js:74:11)
at process._tickCallback (internal/process/next_tick.js:98:9)

[Tue May 31 2016 22:32:02 GMT+0530 (IST)] INFO Connected to Lattermost.

From what I understand looking at client.coffee code, I see that the call to get the list of channels fails. I also don't see any info on the profiles loaded. Although hubot starts fine, I don't get any response when messaging the bot, and for every message I see the below error - which is obviously because the channel info was not fetched earlier.

[Tue May 31 2016 22:38:38 GMT+0530 (IST)] INFO ACK ping
[Tue May 31 2016 22:38:52 GMT+0530 (IST)] ERROR TypeError: Cannot read property 'cjafy4wg47ykzgkpdnrwd6ojsa' of undefined
at Client.getChannelByID (/home/i055636/git/alfred/node_modules/mattermost-client/src/client.coffee:247:9, :333:27)
at Matteruser.message (/home/i055636/git/alfred/node_modules/hubot-matteruser/src/matteruser.coffee:122:21, :195:33)
at Client. (/home/i055636/git/alfred/node_modules/hubot-matteruser/src/matteruser.coffee:1:1, :3:61)
at emitOne (events.js:96:13)
at Client.emit (events.js:188:7)
at Client.onMessage (/home/i055636/git/alfred/node_modules/mattermost-client/src/client.coffee:206:17, :274:23)
at WebSocket. (/home/i055636/git/alfred/node_modules/mattermost-client/src/client.coffee:154:13, :213:22)
at emitTwo (events.js:106:13)
at WebSocket.emit (events.js:191:7)
at Receiver.ontext (/home/i055636/git/alfred/node_modules/ws/lib/WebSocket.js:841:10)
at /home/i055636/git/alfred/node_modules/ws/lib/Receiver.js:536:18
at Receiver.applyExtensions (/home/i055636/git/alfred/node_modules/ws/lib/Receiver.js:371:5)
at /home/i055636/git/alfred/node_modules/ws/lib/Receiver.js:508:14
at Receiver.flush (/home/i055636/git/alfred/node_modules/ws/lib/Receiver.js:347:3)
at Receiver.opcodes.1.finish (/home/i055636/git/alfred/node_modules/ws/lib/Receiver.js:541:12)
at Receiver.expectHandler (/home/i055636/git/alfred/node_modules/ws/lib/Receiver.js:499:31)
at Receiver.add (/home/i055636/git/alfred/node_modules/ws/lib/Receiver.js:103:24)
at TLSSocket.realHandler (/home/i055636/git/alfred/node_modules/ws/lib/WebSocket.js:825:20)
at emitOne (events.js:96:13)
at TLSSocket.emit (events.js:188:7)
at readableAddChunk (_stream_readable.js:172:18)
at TLSSocket.Readable.push (_stream_readable.js:130:10)
at TLSWrap.onread (net.js:542:20)

Could you please let me know how I can fix this? Am I missing something from my end or is this a possible bug?

Regards,
Anand

Unit tests

As developer and contributor I want to ensure that my changes do not break the client.

We should use Jest for testing using the CI setup.

Can you give some suggestion to develop coffescript?

@loafoe Even though I have pushed some code to it, but my development process is really slow! I can't debug in IDE, just add some log to check bug. can you give me some help on it? What I need is to debug code in IDE step by step. BTW, I'm using VSCode.

Sorry I know it's not a good place to ask question here, but I really want to your help. thanks a lot in advance.

TypeError: Cannot read property 'text' of undefined

I am getting the following error. This is on a brand new installation. I also tested on another active Mattermost installation and getting the same error.

[Sun Aug 21 2016 20:07:10 GMT-0400 (EDT)] INFO Reconnecting in 1000ms
[Sun Aug 21 2016 20:07:11 GMT-0400 (EDT)] INFO Attempting reconnect
[Sun Aug 21 2016 20:07:11 GMT-0400 (EDT)] INFO Logging in...
[Sun Aug 21 2016 20:07:11 GMT-0400 (EDT)] DEBUG POST /users/login
[Sun Aug 21 2016 20:07:12 GMT-0400 (EDT)] INFO Websocket URL: wss://mattermost.kregloh.com:443/api/v3/users/websocket
[Sun Aug 21 2016 20:07:12 GMT-0400 (EDT)] INFO Logged in as user "vina" but not connected yet.
[Sun Aug 21 2016 20:07:12 GMT-0400 (EDT)] DEBUG GET /users/initial_load
[Sun Aug 21 2016 20:07:12 GMT-0400 (EDT)] DEBUG Found 2 teams.
[Sun Aug 21 2016 20:07:12 GMT-0400 (EDT)] DEBUG Testing bot-testing == bot-testing
[Sun Aug 21 2016 20:07:12 GMT-0400 (EDT)] DEBUG Found team! raho6b1xojb6pkm87od8ssamdr
[Sun Aug 21 2016 20:07:12 GMT-0400 (EDT)] DEBUG GET /users/profiles/raho6b1xojb6pkm87od8ssamdr
[Sun Aug 21 2016 20:07:12 GMT-0400 (EDT)] DEBUG GET /teams/raho6b1xojb6pkm87od8ssamdr/channels/
[Sun Aug 21 2016 20:07:12 GMT-0400 (EDT)] INFO Connecting...
[Sun Aug 21 2016 20:07:12 GMT-0400 (EDT)] INFO Connected to Mattermost.
[Sun Aug 21 2016 20:07:12 GMT-0400 (EDT)] INFO Starting pinger...
[Sun Aug 21 2016 20:07:12 GMT-0400 (EDT)] DEBUG Found 2 profiles.
[Sun Aug 21 2016 20:07:12 GMT-0400 (EDT)] DEBUG Found 3 channels.
[Sun Aug 21 2016 20:07:42 GMT-0400 (EDT)] INFO ping
[Sun Aug 21 2016 20:07:42 GMT-0400 (EDT)] ERROR TypeError: Cannot read property 'text' of undefined
at Client.onMessage (/home/joseph/vina/node_modules/hubot-matteruser/node_modules/mattermost-client/src/client.coffee:224:20, :295:28)
at WebSocket. (/home/joseph/vina/node_modules/hubot-matteruser/node_modules/mattermost-client/src/client.coffee:159:13, :218:22)
at WebSocket.emit (events.js:98:17)
at Receiver.ontext (/home/joseph/vina/node_modules/hubot-matteruser/node_modules/mattermost-client/node_modules/ws/lib/WebSocket.js:841:10)
at /home/joseph/vina/node_modules/hubot-matteruser/node_modules/mattermost-client/node_modules/ws/lib/Receiver.js:536:18
at Receiver.applyExtensions (/home/joseph/vina/node_modules/hubot-matteruser/node_modules/mattermost-client/node_modules/ws/lib/Receiver.js:371:5)
at /home/joseph/vina/node_modules/hubot-matteruser/node_modules/mattermost-client/node_modules/ws/lib/Receiver.js:508:14
at Receiver.flush (/home/joseph/vina/node_modules/hubot-matteruser/node_modules/mattermost-client/node_modules/ws/lib/Receiver.js:347:3)
at Receiver.opcodes.1.finish (/home/joseph/vina/node_modules/hubot-matteruser/node_modules/mattermost-client/node_modules/ws/lib/Receiver.js:541:12)
at Receiver.expectHandler (/home/joseph/vina/node_modules/hubot-matteruser/node_modules/mattermost-client/node_modules/ws/lib/Receiver.js:499:31)
at Receiver.add (/home/joseph/vina/node_modules/hubot-matteruser/node_modules/mattermost-client/node_modules/ws/lib/Receiver.js:103:24)
at CleartextStream.realHandler (/home/joseph/vina/node_modules/hubot-matteruser/node_modules/mattermost-client/node_modules/ws/lib/WebSocket.js:825:20)
at CleartextStream.emit (events.js:95:17)
at CleartextStream. (stream_readable.js:765:14)
at CleartextStream.emit (events.js:92:17)
at emitReadable
(_stream_readable.js:427:10)
at _stream_readable.js:420:7
at process._tickCallback (node.js:458:13)

Resolve eslint errors

We'll have to resolve the following issues (add eslint ignore comments and fixing some things):

yarn run v1.19.0
$ eslint src

/Users/danielruf/projects/mattermost-client/src/client.js
  108:78  error  Do not nest ternary expressions                                                                                                                                            no-nested-ternary
  121:5   error  Expected to return a value at the end of method '_onLoadUsers'                                                                                                             consistent-return
  123:13  error  iterators/generators require regenerator-runtime, which is too heavyweight for this guide to allow them. Separately, loops should be avoided in favor of array iterations  no-restricted-syntax
  137:5   error  Expected to return a value at the end of method '_onLoadUser'                                                                                                              consistent-return
  146:13  error  iterators/generators require regenerator-runtime, which is too heavyweight for this guide to allow them. Separately, loops should be avoided in favor of array iterations  no-restricted-syntax
  181:13  error  iterators/generators require regenerator-runtime, which is too heavyweight for this guide to allow them. Separately, loops should be avoided in favor of array iterations  no-restricted-syntax
  224:29  error  Assignment to function parameter 'page'                                                                                                                                    no-param-reassign
  237:29  error  Assignment to function parameter 'page'                                                                                                                                    no-param-reassign
  281:13  error  Return statement should not contain assignment                                                                                                                             no-return-assign
  287:1   error  This line has a length of 109. Maximum allowed is 100                                                                                                                      max-len
  291:21  error  Arrow function expected no return value                                                                                                                                    consistent-return
  294:17  error  Arrow function expected no return value                                                                                                                                    consistent-return
  301:45  error  Expected to return a value at the end of arrow function                                                                                                                    consistent-return
  310:9   error  Method 'connect' expected no return value                                                                                                                                  consistent-return
  330:9   error  Unary operator '++' used                                                                                                                                                   no-plusplus
  414:5   error  Expected to return a value at the end of method 'getUserByEmail'                                                                                                           consistent-return
  415:9   error  for..in loops iterate over the entire prototype chain, which is virtually never what you want. Use Object.{keys,values,entries}, and iterate over the resulting array      no-restricted-syntax
  436:9   error  Method 'getUserDirectMessageChannel' expected no return value                                                                                                              consistent-return
  451:13  error  Assignment to property of function parameter 'postData'                                                                                                                    no-param-reassign
  453:9   error  Assignment to property of function parameter 'postData'                                                                                                                    no-param-reassign
  458:17  error  Assignment to property of function parameter 'postData'                                                                                                                    no-param-reassign
  522:85  error  Expected to return a value at the end of arrow function                                                                                                                    consistent-return
  529:9   error  for..in loops iterate over the entire prototype chain, which is virtually never what you want. Use Object.{keys,values,entries}, and iterate over the resulting array      no-restricted-syntax
  530:1   error  This line has a length of 107. Maximum allowed is 100                                                                                                                      max-len
  537:18  error  Expected 'this' to be used by class method '_chunkMessage'                                                                                                                 class-methods-use-this
  576:17  error  Assignment to function parameter 'msg'                                                                                                                                     no-param-reassign
  603:9   error  Assignment to property of function parameter 'message'                                                                                                                     no-param-reassign
  603:22  error  Unary operator '++' used                                                                                                                                                   no-plusplus
  604:9   error  Assignment to property of function parameter 'message'                                                                                                                     no-param-reassign
  615:13  error  Assignment to function parameter 'method'                                                                                                                                  no-param-reassign
  617:40  error  Assignment to function parameter 'callback_params'                                                                                                                         no-param-reassign
  645:53  error  Expected to return a value at the end of arrow function                                                                                                                    consistent-return
  653:25  error  Assignment to function parameter 'value'                                                                                                                                   no-param-reassign

/Users/danielruf/projects/mattermost-client/src/message.js
  3:22  error  Assignment to function parameter 'data'                                                                                                                                no-param-reassign
  4:9   error  for..in loops iterate over the entire prototype chain, which is virtually never what you want. Use Object.{keys,values,entries}, and iterate over the resulting array  no-restricted-syntax
  4:9   error  The body of a for-in should be wrapped in an if statement to filter unwanted properties from the prototype                                                             guard-for-in

/Users/danielruf/projects/mattermost-client/src/user.js
  3:22  error  Assignment to function parameter 'data'                                                                                                                                no-param-reassign
  4:9   error  for..in loops iterate over the entire prototype chain, which is virtually never what you want. Use Object.{keys,values,entries}, and iterate over the resulting array  no-restricted-syntax
  4:9   error  The body of a for-in should be wrapped in an if statement to filter unwanted properties from the prototype                                                             guard-for-in

✖ 39 problems (39 errors, 0 warnings)

error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

listening to post reactions

We have a fun need of sending a kick command if a message gets a fixed number of a defined reaction (let's say hammer)

I don't see any get_reaction or related method, is there a way to do this already ?

Mattermost 3.4 Support

Does this system support Mattermost 3.4 yet? I've had a few issues successfully connecting a hubot instance to Mattermost, from the debugging I've managed to do so far, it looks like there is an issue when trying to login, which is handled in this repo?

What can I provide in order to help figure this out?

startup showing errors

I am just getting started with mattermost-user and getting this in the hubot log:

INFO Logging in...
INFO Websocket URL: wss://ouraddress:443/api/v1/websocket
INFO Logged in as user "bot" but not connected yet.
INFO Connecting...
INFO Connected to Mattermost.
INFO Starting pinger...
DEBUG Found 3 profiles.
DEBUG Found 5 channels.
DEBUG Found 13 teams.
ERROR { [Error: getaddrinfo ENOTFOUND] code: 'ENOTFOUND', errno: 'ENOTFOUND', syscall: 'getaddrinfo' }
ERROR { [Error: getaddrinfo ENOTFOUND] code: 'ENOTFOUND', errno: 'ENOTFOUND', syscall: 'getaddrinfo' }
ERROR { [Error: getaddrinfo ENOTFOUND] code: 'ENOTFOUND', errno: 'ENOTFOUND', syscall: 'getaddrinfo' }
ERROR { [Error: getaddrinfo ENOTFOUND] code: 'ENOTFOUND', errno: 'ENOTFOUND', syscall: 'getaddrinfo' }
ERROR { [Error: getaddrinfo ENOTFOUND] code: 'ENOTFOUND', errno: 'ENOTFOUND', syscall: 'getaddrinfo' }
ERROR { [Error: getaddrinfo ENOTFOUND] code: 'ENOTFOUND', errno: 'ENOTFOUND', syscall: 'getaddrinfo' }
ERROR { [Error: getaddrinfo ENOTFOUND] code: 'ENOTFOUND', errno: 'ENOTFOUND', syscall: 'getaddrinfo' }
INFO ping
INFO ACK ping

Is this ping related? I cannot find the related logger code. My bot commands also do not seem to be working.

Update to newest api? (v3)

As stated in release note:

Web Service API is upgraded to Version 3 and previous Version 1 API is no longer supported. Golang driver, Javascript driver, incoming and outgoing webhooks and Slash commands continue to function as in previous release

Will we see an update?

Examples (docs)

As a user I need some examples to know what and how I can use it.
Also versioned docs might be a good idea.

Need some assistance

The Docker Build and Run went fine and I was put into the hubot cli when I ran the container.

[jonathanKlein@mattermost-demo-docker-instance hubot-matteruser]$ sudo docker run -it -p 8080:8080 --env MATTERMOST_HOST=chat.pwcdatasieve.com --env MATTERMOST_GROUP=innovation --env MATTERMOST_USER=jarvis@pwc --env MATTERMOST_PASSWORD=BotsAreCool --env MATTERMOST_SELFSIGNED_CERT=true --env MATTERMOST_HUBOT_USERNAME=jarvis --env --name hubot-matteruser hubot-matteruser
npm info it worked if it ends with ok
npm info using [email protected]
npm info using [email protected]
npm info preinstall [email protected]
npm info package.json [email protected] No license field.
npm info build /usr/src/hubot-matteruser
npm info linkStuff [email protected]
npm info install [email protected]
npm info postinstall [email protected]
npm info prepublish [email protected]
npm info ok
jarvis> [Thu Oct 19 2017 14:23:08 GMT+0000 (UTC)] INFO hubot-redis-brain: Using default redis on localhost:6379

jarvis>
jarvis> jarvis help
jarvis> jarvis adapter - Reply with the adapter
ETC…

do I also need the mattermost-client installed?
github.com

loafoe/mattermost-client

mattermost-client - Mattermost client using websockets
I having trouble following the steps in the installation instructions.

Thanks!

Add emit event for 'channelsLoaded'

In client.coffee:

Similar to 'ProfilesLoaded' in line 91.
@emit 'profilesLoaded', { profiles: @users }

the _onChannels method should emit a 'channelsLoaded' event to be able to initially contact all users on startup.

=> Should be
@emit 'channelsLoaded', { channels: @channels }
below line 98

"I needed this function for an internal survey, where a chatbot sent the initial message!"

TypeError when handling message after new user connects

When using the hubot-matteruser adaptor for hubot I've noticed that whenever a new user connects, the next message to hubot seem to fail with a TypeError:

Fri May 27 2016 13:03:55 GMT-0600 (MDT) [APP] OUT [Fri May 27 2016 19:03:55 GMT+0000 (UTC)] DEBUG GET /users/profiles��
Fri May 27 2016 13:03:55 GMT-0600 (MDT) [APP] OUT [Fri May 27 2016 19:03:55 GMT+0000 (UTC)] DEBUG Found 2 profiles.��
Fri May 27 2016 13:04:06 GMT-0600 (MDT) [APP] OUT [Fri May 27 2016 19:04:06 GMT+0000 (UTC)] ERROR TypeError: Cannot read property 'username' of undefined��
Fri May 27 2016 13:04:06 GMT-0600 (MDT) [APP] OUT at Client.<anonymous> (/home/vcap/app/node_modules/hubot-matteruser/src/matteruser.coffee:1:1, <js>:3:61)��
Fri May 27 2016 13:04:06 GMT-0600 (MDT) [APP] OUT at Matteruser.message (/home/vcap/app/node_modules/hubot-matteruser/src/matteruser.coffee:126:29, <js>:199:64)��
Fri May 27 2016 13:04:06 GMT-0600 (MDT) [APP] OUT at Client.emit (events.js:95:17)��
Fri May 27 2016 13:04:06 GMT-0600 (MDT) [APP] OUT at Client.onMessage (/home/vcap/app/node_modules/mattermost-client/src/client.coffee:206:17, <js>:274:23)��
Fri May 27 2016 13:04:06 GMT-0600 (MDT) [APP] OUT at WebSocket.<anonymous> (/home/vcap/app/node_modules/mattermost-client/src/client.coffee:154:13, <js>:213:22)��
Fri May 27 2016 13:04:06 GMT-0600 (MDT) [APP] OUT at WebSocket.emit (events.js:98:17)��
Fri May 27 2016 13:04:06 GMT-0600 (MDT) [APP] OUT at Receiver.ontext (/home/vcap/app/node_modules/ws/lib/WebSocket.js:841:10)��
Fri May 27 2016 13:04:06 GMT-0600 (MDT) [APP] OUT at /home/vcap/app/node_modules/ws/lib/Receiver.js:536:18��
Fri May 27 2016 13:04:06 GMT-0600 (MDT) [APP] OUT at Receiver.applyExtensions (/home/vcap/app/node_modules/ws/lib/Receiver.js:371:5)��
Fri May 27 2016 13:04:06 GMT-0600 (MDT) [APP] OUT at /home/vcap/app/node_modules/ws/lib/Receiver.js:508:14��
Fri May 27 2016 13:04:06 GMT-0600 (MDT) [APP] OUT at Receiver.flush (/home/vcap/app/node_modules/ws/lib/Receiver.js:347:3)��
Fri May 27 2016 13:04:06 GMT-0600 (MDT) [APP] OUT at Receiver.expectHandler (/home/vcap/app/node_modules/ws/lib/Receiver.js:499:31)��
Fri May 27 2016 13:04:06 GMT-0600 (MDT) [APP] OUT at Receiver.opcodes.1.finish (/home/vcap/app/node_modules/ws/lib/Receiver.js:541:12)��
Fri May 27 2016 13:04:06 GMT-0600 (MDT) [APP] OUT at Receiver.add (/home/vcap/app/node_modules/ws/lib/Receiver.js:103:24)��
Fri May 27 2016 13:04:06 GMT-0600 (MDT) [APP] OUT at CleartextStream.realHandler (/home/vcap/app/node_modules/ws/lib/WebSocket.js:825:20)��
Fri May 27 2016 13:04:06 GMT-0600 (MDT) [APP] OUT at CleartextStream.emit (events.js:95:17)��
Fri May 27 2016 13:04:06 GMT-0600 (MDT) [APP] OUT at CleartextStream.<anonymous> (_stream_readable.js:765:14)��
Fri May 27 2016 13:04:06 GMT-0600 (MDT) [APP] OUT at CleartextStream.emit (events.js:92:17)��
Fri May 27 2016 13:04:06 GMT-0600 (MDT) [APP] OUT at emitReadable_ (_stream_readable.js:427:10)��
Fri May 27 2016 13:04:06 GMT-0600 (MDT) [APP] OUT at _stream_readable.js:420:7��
Fri May 27 2016 13:04:06 GMT-0600 (MDT) [APP] OUT at process._tickCallback (node.js:458:13)��

I've poked around the code a bit and I think it might be because of an incorrect url in client.coffee#L215.

The team is missing from the URL which seems to result in a 404.

Unable to post messages with unicode characters

If there is a unicode character in the message the post request will fail with no error. The mattermost log display this message:
[EROR] /api/v1/channels//create:createPost code=400 rid= uid= ip= Invalid post parameter [details: ]

CI

We should run all tests on every push and PR.
I recommend GitHub Actions for this.

And we should run eslint checks.

  • test on NodeJS 8
  • test on NodeJS 10
  • test on NodeJS 12
  • test on NodeJS latest
  • run eslint
  • use npm-run-all

defaultPingInterval missing

I had an issue on a new installation in node_modules/mattermost-client/src/client.coffee
the defaultPingInterval was missing.
You probably should rename the pingInterval on top to defaultPingInterval
At least then it was working for me.

mattermost-client as proxy

Is this possible to use mattermost-client as proxy to mm server ? so that users can login from any 'participating website'

OAuth support

Is it possible to add OAuth support for login?

My Mattermost is linked to a GitLab. So, authentication is made on GitLab and access to Mattermost is provided via OAuth.

Looking around, it seems there is some piece of code to handle OAuth authentication:

I can do hacking and test on my environment. But as I'm not really comfortable with JavaScript yet, I will appreciate some help to design the solution.
@railsguru do you have any suggestion on how to provide this authentication method on the current API?

When no TLS, websocket still use port 443

Hi there,

If someone set websocket to not use TLS, it still uses port 443 due to ternary operation at line 59.

@socketUrl = (if useTLS then 'wss://' else 'ws://') + @host + (if @options.wssPort? then ':'+ @options.wssPort else ':443') + apiPrefix + usersRoute + '/websocket'

While in fact user can override this by passing a parameter to the constructor, when using hubot-matteruser , if user set MATTERMOST_USE_TLS it should implicit no SSL ports (neither https nor wss) but it still defaults to TSL port 443. This default should be conditioned to use of TLS at all.

_onInitialLoad sometimes fails with "Object.keys called on non-object

I use mattermost-client as part of hubot-matteruser, and every once in a while i will notice that hubot is no longer logged in.

When i look at the logs i see something like this:

2016-06-06T23:31:47.76-0600 [APP/0]      OUT [Tue Jun 07 2016 05:31:47 GMT+0000 (UTC)] ERROR Last pong is too old: 113.898
2016-06-06T23:31:47.76-0600 [APP/0]      OUT [Tue Jun 07 2016 05:31:47 GMT+0000 (UTC)] INFO Reconnecting in 1000ms
2016-06-06T23:31:48.76-0600 [APP/0]      OUT [Tue Jun 07 2016 05:31:48 GMT+0000 (UTC)] INFO Attempting reconnect
2016-06-06T23:31:48.76-0600 [APP/0]      OUT [Tue Jun 07 2016 05:31:48 GMT+0000 (UTC)] INFO Logging in...
2016-06-06T23:31:48.76-0600 [APP/0]      OUT [Tue Jun 07 2016 05:31:48 GMT+0000 (UTC)] DEBUG POST /users/login
2016-06-06T23:31:48.97-0600 [APP/0]      OUT [Tue Jun 07 2016 05:31:48 GMT+0000 (UTC)] INFO Websocket URL: wss://mattermost.example.com:443/api/v3/users/websocket
2016-06-06T23:31:48.97-0600 [APP/0]      OUT [Tue Jun 07 2016 05:31:48 GMT+0000 (UTC)] INFO Logged in as user "hubot" but not connected yet.
2016-06-06T23:31:48.97-0600 [APP/0]      OUT [Tue Jun 07 2016 05:31:48 GMT+0000 (UTC)] DEBUG GET /users/initial_load
2016-06-06T23:31:49.11-0600 [APP/0]      OUT [Tue Jun 07 2016 05:31:49 GMT+0000 (UTC)] ERROR TypeError: Object.keys called on non-object
2016-06-06T23:31:49.11-0600 [APP/0]      OUT   at Function.keys (native)        
2016-06-06T23:31:49.11-0600 [APP/0]      OUT   at Client._onInitialLoad (/home/vcap/app/node_modules/mattermost-client/src/client.coffee:68:13, <js>:100:45)
2016-06-06T23:31:49.11-0600 [APP/0]      OUT   at /home/vcap/app/node_modules/mattermost-client/src/client.coffee:1:1, <js>:3:61
2016-06-06T23:31:49.11-0600 [APP/0]      OUT   at IncomingMessage.<anonymous> (/home/vcap/app/node_modules/mattermost-client/src/client.coffee:313:25, <js>:433:22)
2016-06-06T23:31:49.11-0600 [APP/0]      OUT   at IncomingMessage.emit (events.js:117:20)
2016-06-06T23:31:49.11-0600 [APP/0]      OUT   at _stream_readable.js:944:16    
2016-06-06T23:31:49.11-0600 [APP/0]      OUT   at process._tickCallback (node.js:458:13)


I suspect this is due to some error condition in _apiCall. On error the the method calls callback, but with a special error object. Unfortunately it doesn't look like any users of _apiCall bother to check whether or not an error occurred...

Feature: Additional (optional) headers to options

See also #57

Add headers option to options like

{
   wssPort: 443, 
   httpPort: 80, 
   headers: {'X-Requested-With': 'XMLHttpRequest', 'date': '123', [...]} 
}

and merge with existing headers like Object.assign({}, existingHeaders, this.options.headers)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.