mattermost / mattermost

Mattermost is an open source platform for secure collaboration across the entire software development lifecycle..
https://mattermost.com
Other
30.7k stars 7.37k forks source link

mmctl: add ability to send direct messages #19914

Open mattermod opened 2 years ago

mattermod commented 2 years ago

mmctl can be used to send direct messages. With an easier way of using a command like mmctl post create team:@user --message "message".


If you're interested please comment here and come join our "Contributors" community channel on our daily build server, where you can discuss questions with community members and the Mattermost core team. For technical advice or questions, please join our "Developers" community channel.

New contributors please see our Developer's Guide.

JIRA: https://mattermost.atlassian.net/browse/MM-40525

woat commented 2 years ago

Can I take this one?

ChandanChainani commented 1 year ago

@amyblais we have a command available to create post using team and channel information

mmctl post create myteam:mychannel --message "some text for the post"

As per my understanding mentioned requirement is not possible since team can have many channels so it is not possible to select specific channel to create post in without channel information.

amyblais commented 1 year ago

we have a command available to create post using team and channel information

mmctl post create myteam:mychannel --message "some text for the post"

As per my understanding mentioned requirement is not possible since team can have many channels so it is not possible to select specific channel to create post in without channel information.

cc @isacikgoz

isacikgoz commented 1 year ago

@ChandanChainani this is possible through multiple steps.

Kimbohlovette commented 1 year ago

Hello @hanzei. Please I want to work on this issue

hanzei commented 1 year ago

Awesome, thanks @Kimbohlovette :+1:

Kimbohlovette commented 12 months ago

Hello @hanzei, @isacikgoz Please I have a block on this issue

I have followed the steps @isacikgoz outlined above as follows

  1. Created a cobra command PostCreateDirectMessageCmd in cmd/mmctl/commands/post.go with its associated function PostCreateDirectMessageCmdF.
  2. In the PostCreateDirectMessageCmdF function, I collected the team and user parts from argument with the getTeamFromTeamArg and getUserFromUserArg functions.
  3. Collected the message flag with the cmd.Flags().GetString() method.
  4. To check if users can talk to each other, this is my approach Get users in team using c.GetUsersInTeam() method Check if both users belong to this list of users. Unfortunately for me the c.GetUsersInTeam() needs the pagination parameters (page and perPage). Please how can I check to see if two users belong to a team?
Kimbohlovette commented 11 months ago

Hello @hanzei, I still need your help here :pray:

hanzei commented 11 months ago

Do we even need to check if the user is a member of a given team? The REST API call will fail anyway if that is not the case.

Another thought: Do we even need the --message flag? Can we simplify here and use mmctl post create myteam:mychannel "some text for the post"?

Kimbohlovette commented 11 months ago

Do we even need to check if the user is a member of a given team? The REST API call will fail anyway if that is not the case.

Another thought: Do we even need the --message flag? Can we simplify here and use mmctl post create myteam:mychannel "some text for the post"?

The aim was to be able to send a message directly to someone with a command such like mmctl post create myteam:@someuser "message"

Kimbohlovette commented 11 months ago

mmctl can be used to send direct messages. With an easier way of using a command like mmctl post create team:@user --message "message".

If you're interested please comment here and come join our "Contributors" community channel on our daily build server, where you can discuss questions with community members and the Mattermost core team. For technical advice or questions, please join our "Developers" community channel.

New contributors please see our Developer's Guide.

JIRA: https://mattermost.atlassian.net/browse/MM-40525

Like here

Kimbohlovette commented 11 months ago

@ChandanChainani this is possible through multiple steps.

  • You'll need to provide a team to see if these two users can see each other.
  • Create direct channel (this will return the direct channel if it's already created) via API. To get the channel you just need to provide the users ids ref
  • You'll use the channel ID to post the message

Also look at these steps outlined here. It it shows that we need to make sure that both users are in the team provided. That is why I chose to get all the users for that team and check if both sender and receiver are there

Kimbohlovette commented 11 months ago

@hanzei I still need more clarification on how to implement this issue. Could place give me some minutes of your time to clarify me please?

isacikgoz commented 11 months ago

@Kimbohlovette I agree with @hanzei on the message should be in the form of the argument rather than a flag. You can scrape that information from the cmd.Args.

Kimbohlovette commented 11 months ago

@Kimbohlovette I agree with @hanzei on the message should be in the form of the argument rather than a flag. You can scrape that information from the cmd.Args.

Okay noted @isacikgoz.

Kimbohlovette commented 11 months ago

And about making sure both users see each other should I still enforce that or I should let the server to handle that?

Kimbohlovette commented 11 months ago

@Kimbohlovette I agree with @hanzei on the message should be in the form of the argument rather than a flag. You can scrape that information from the cmd.Args.

Hello sir, how do I get the message from a command here using cmd.Args please?

Kimbohlovette commented 11 months ago

@hanzei , @isacikgoz please I may be getting something wrongly in this task What does it mean to send direct messages? Does the command sends a single message to everyone in the team or it sends a single message to just one person? And I will also appreciate if you guys help me complete this task as fast as possible. Many thanks

hanzei commented 11 months ago

Hi @Kimbohlovette,

The ticket is about sending a direct messages to another user.

cmd.Args[0] contains the first argument that was passed to the command.

Kimbohlovette commented 11 months ago

Hi @Kimbohlovette,

The ticket is about sending a direct messages to another user.

cmd.Args[0] contains the first argument that was passed to the command.

okay

Kimbohlovette commented 9 months ago

Hello @hanzei

hanzei commented 9 months ago

Hi @Kimbohlovette.

Is there anything I can help you with?

Kimbohlovette commented 7 months ago

Hello @hanzei you proposed that we should implement this send DM command as

mmctl post create team:@user "some direct mesage"

Currently we have the create post command to send a message to a channel in a team

mmctl post create team:channel --message "some message to channel"

My observation is that these commands are basically thesame with differences only in the way arguments are passed.

I am proposing that we should extend the command

mmctl post create team:channel --message "some channel message"

to

mmctl post create team:[channel | @user] --message "some message"

and then handle the [channel | @user] section of the argument in the postCreateFn by checking if a valid user exists in args[0] as below

Screen Shot 2024-03-21 at 12 49 37 PM

Please I would like to hear your view on this

hanzei commented 7 months ago

Do we even need the team in team:@user?

Kimbohlovette commented 7 months ago

What you're saying is correct we do not need it even from the beginning

Screen Shot 2024-03-22 at 11 47 59 AM
Kimbohlovette commented 7 months ago

One thing to note would be to check how getChannelFromChannelArg() parses the argument team:[channel | user]. Same with the getUserFromUserArg() function

Kimbohlovette commented 7 months ago

Hello @hanzei I would like you to have a final say on this issue so that I can work

hanzei commented 7 months ago

Are you sure that getUserFromUserArg requires the team:user format? I think it use a simple userID|username|email format.

Kimbohlovette commented 7 months ago

I just checked it's safe to use getUserFromUserArg even when we scrap out the team section

Kimbohlovette commented 7 months ago

Hello @hanzei I opened a PR for this issue [GH-19914] Adds ability to send direct message #26602 I will be waiting for your reviews Thanks

hanzei commented 7 months ago

Awesome! I will take a look tomorrow.

Kimbohlovette commented 7 months ago

Thanks 😊