GithubHelp home page GithubHelp logo

Comments (11)

marcesher avatar marcesher commented on June 12, 2024 3

hey @loafoe thanks a lot for the response so quickly!

I confirmed the behavior you describe and was able to send a DM if I hard-coded the channel for an existing conversation between a bot and a human. That's progress, insofar as it demonstrates feasibility.

Let me ask you this: I was poking around in your mattermost-client, and it looks like matteruser delegates most functionality to that, which is cool. So if MM exposed some kind of server API that, I don't know, initiated a channel between one user and another, then conceivably the client could call that, and matteruser could hook into that somehow (new command, message.privateMessage() or whatever) and under the hood it'd just set the envelope room to the channel from the API call.

Does that at least conceptually sound feasible?

I realize it'd involve working with the MM folks to actually expose that API, and that'd take some time -- assuming they were even OK with that -- but right now I'm just trying to think through the mechanics of how this might work. Baby steps, and all that.

Thanks again for such a kick-ass piece of software! I've worked in OSS for a long time, and I know thanks are few and far between. I want you to know we're getting tons of mileage out of what you've written here. ✊ 👍

from hubot-matteruser.

loafoe avatar loafoe commented on June 12, 2024

@marcesher a DM between two users actually happens in a unique channel which have sender/receiver as the only members (AFAIK). So instead of the user id you would need to use the room ID of this DM channel. However there does not seem to be a way to look up this DM room ID as of now.
But very interesting idea! I'll dig in a bit to find out more. If it's not available it could even be a nice feature request towards the Mattermost team.

Note: You can anyway find out the room ID of this DM channel by cranking up the debug level of the bot and capturing the room ID when you manually send a DM message to the bot.

from hubot-matteruser.

marcesher avatar marcesher commented on June 12, 2024

Oh, and re: I realize it'd involve working with the MM folks to actually expose that API, and that'd take some time I don't mean to suggest at all that you'd do that. I don't mean to equate any of this to more work on your part. I'm just looking for conceptual direction or advice, if you have it.

from hubot-matteruser.

loafoe avatar loafoe commented on June 12, 2024

@marcesher appreciate your thanks! :-)

So thinking about this one possible solution might be to have sort of a one time activation of a user to the bot i.e. the user would need to send at least one DM to your bot. The bot would then immediately capture and store the DM room ID for that user in some way so it can use it for future bot initiated DM communication back to the user! It might work if your use-case can handle this one time activation step?

So conceptually it will work for sure, in fact that is one of the main reason I'm writing this stuff: I want to use Mattermost as a sort of command-and-control for all sorts of external service activations and status lookups within our team. Having various bots respond directly via DM is almost required! :)

from hubot-matteruser.

loafoe avatar loafoe commented on June 12, 2024

@contolini accepted the challenge and implemented bot initiated DMs! /cc @marcesher

from hubot-matteruser.

Judokus avatar Judokus commented on June 12, 2024

The functions getUserDirectMessageChannel and channelInfo don't call the correct API:
api/v3/channels/channel_id instead of api/v3/teams/team_id/channels/channel_id ?

Also, when doing robot.send {"room":"judokus"}, message the bot sends the message to multiple rooms where I and the bot are in. Sometimes all of them, sometimes just one or two channels...

from hubot-matteruser.

contolini avatar contolini commented on June 12, 2024

@Judokus Sounds like this needs more testing. I admittedly only have access to v1 of the API at the moment.

The functions getUserDirectMessageChannel and channelInfo don't call the correct API:
api/v3/channels/channel_id instead of api/v3/teams/team_id/channels/channel_id ?

In client.coffee

@_apiCall 'POST', '/channels/create_direct', postData, (data, headers) =>

is likely incorrect and should be changed to

@_apiCall 'POST', @teamRoute() + '/channels/create_direct', postData, (data, headers) =>

to account for multiple teams.

Also, when doing robot.send {"room":"judokus"}, message the bot sends the message to multiple rooms where I and the bot are in. Sometimes all of them, sometimes just one or two channels...

If it's messaging multiple rooms, this logic needs to be tweaked.

from hubot-matteruser.

Judokus avatar Judokus commented on June 12, 2024

Yep, it works with that change (or @channelRoute('/create_direct'))

About the logic, I actually tried it a bit different to find the DM channel in v1. Mattermost saves the DM channel names as userID__userID so I did:

  • find the channel with name botID__userID in @channel_details
  • if it doesn't exist, try it the other way around userID__botID
  • else just create the channel with /create_direct

from hubot-matteruser.

contolini avatar contolini commented on June 12, 2024

Yep, it works with that change (or @channelRoute('/create_direct'))

Nice!

About the logic, I actually tried it a bit different to find the DM channel in v1. Mattermost saves the DM channel names as userID__userID

Ah, very clever. Does that technique work with v3?

from hubot-matteruser.

Judokus avatar Judokus commented on June 12, 2024

Yes. Just tested this with the following:

    # check if channel already exists
    channel = robot.adapter.client.self.id + "__" + user.id
    channel = robot.adapter.client.findChannelByName(channel)
    if !channel
      # check if channel in other direction exists
      channel = user.id + "__" + robot.adapter.client.self.id
      channel = robot.adapter.client.findChannelByName(channel)
      if !channel
        # channel obviously doesn't exist, let's create it
        channel = robot.adapter.client.createDirectChannel(user.id)
        if !channel
          res.send "Kon DM kanaal niet aanmaken"
    createDirectChannel: (user_id) ->
        postData = 
            user_id: user_id
        @_apiCall 'POST', '/channels/create_direct', postData, (data, header) =>
            @logger.debug 'Created Direct Channel.'
            return data

    findChannelByName: (name) ->
        for c of @channel_details
            if @channel_details[c].name == name or @channel_details[c].display_name == name
                return @channel_details[c]

There is probably a neater way to write it..

from hubot-matteruser.

loafoe avatar loafoe commented on June 12, 2024

Fixed and tested in 3.1.0

from hubot-matteruser.

Related Issues (20)

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.