Comments (6)
Well originally, before I made the changes, the code always just returned the sender name regardless of user_id given or not. So I will go ahead and merge the change in to at least restore the way it worked when user_id is None. Thanks for digging into the details of how the username override stuff actually works.
from mmpy_bot.
There is a chance that username(user_id) != sender_name
.
When sending post through webhook, there is a parameter username
which can overrides the username the message posts as if EnablePostUsernameOverride
is set to true
.
Example 1 : EnablePostUsernameOverride = false
For example, if we send a hello post through webhook with username = "mockname"
when EnablePostUsernameOverride = false
(default), the post will look like this :
{'event': 'posted', 'data': {'channel_display_name': 'Off-Topic', 'channel_name': 'off-topic', 'channel_type': 'O', 'post': {'id': 'hu8s8abo3fy69xt7nwfm1fq3ka', 'create_at': 1531852142221, 'update_at': 1531852142221, 'edit_at': 0, 'delete_at': 0, 'is_pinned': False, 'user_id': 'ta7a1ceamt8kiegt445emo6e5h', 'channel_id': '4fgt3n51f7ftpff91gk1iy1zow', 'root_id': '', 'parent_id': '', 'original_id': '', 'message': 'hello', 'type': '', 'props': {'from_webhook': 'true'}, 'hashtags': '', 'pending_post_id': ''}, 'sender_name': 'amy', 'team_id': 'au64gza3iint3r31e7ewbrrasw'}, 'broadcast': {'omit_users': None, 'user_id': '', 'channel_id': '4fgt3n51f7ftpff91gk1iy1zow', 'team_id': ''}, 'seq': 2, 'message_type': '?'}
The name displayed on MM channel will be amy [bot].
Example 2 : EnablePostUsernameOverride = true
And if it is sent when EnablePostUsernameOverride = true
, the post will be :
{'event': 'posted', 'data': {'channel_display_name': 'Off-Topic', 'channel_name': 'off-topic', 'channel_type': 'O', 'post': {'id': '45o6whbrp3no5djmg5iabm14ky', 'create_at': 1531879612382, 'update_at': 1531879612382, 'edit_at': 0, 'delete_at': 0, 'is_pinned': False, 'user_id': 'ta7a1ceamt8kiegt445emo6e5h', 'channel_id': '4fgt3n51f7ftpff91gk1iy1zow', 'root_id': '', 'parent_id': '', 'original_id': '', 'message': 'hello', 'type': '', 'props': {'from_webhook': 'true', 'override_username': 'mockname'}, 'hashtags': '', 'pending_post_id': ''}, 'sender_name': 'mockname', 'team_id': 'au64gza3iint3r31e7ewbrrasw'}, 'broadcast': {'omit_users': None, 'user_id': '', 'channel_id': '4fgt3n51f7ftpff91gk1iy1zow', 'team_id': ''}, 'seq': 2, 'message_type': '?'}
The name displayed on MM channel will be mockname [bot].
Diff
Both posts are sent by the same user account, so the user_id
is also the same. But example2 has sender_name
overridden, and an additional override_username
.
So I think the current code is fine since it returns the actual username by user_id.
def get_username(self, user_id=None):
return self.get_user_info('username', user_id)
If developers need to get sender_name or override_username, maybe we should consider expose them as public methods ?
from mmpy_bot.
When the user_id paramter is provided to Message.get_username(user_id) I totally agree with you we should lookup the username by the user_id. However, we should try to think about the intent of calling Message.get_username() when no parameter is given. In that case in my opinion the most logical intent seems to be to get the username seen in the channel for that message, regardless of the fact that it could be overridden. Does that make sense @seLain?
We could expose both sender_name and override_username if you think those are also needed.
from mmpy_bot.
Well, I just thought originally get_username
would return the actual username. So I tried to make clear if username(user_id) != sender_name
in some cases.
If the intention is to get the username seen in the channel for that message when user_id is given none, I am ok with the change :)
from mmpy_bot.
@attzonko I am trying to use get_user_info(USER_ID) but I want it to get the USER_ID dynamically. is there any method to use for this purpose? basically I cannot hard code the USER_ID and I want the script to pull out the user ID of the person talking to the BOT.
from mmpy_bot.
@attzonko I am trying to use get_user_info(USER_ID) but I want it to get the USER_ID dynamically. is there any method to use for this purpose? basically I cannot hard code the USER_ID and I want the script to pull out the user ID of the person talking to the BOT.
I think you want to use just message.get_username()
from mmpy_bot.
Related Issues (20)
- Send a message direct to user who joins room HOT 2
- RuntimeError: this event loop is already running. HOT 9
- No connection with docker image 2.0.0 and MM7.1.3 HOT 2
- Improvement: Add `type` optional param for `create_post(...)` function HOT 7
- Unable to run concurrent asyncio processes HOT 5
- [Question] Register plugins at runtime HOT 1
- Scheduled responses to channel instead of reply HOT 5
- How to send files to bot directly for some postpone processing? HOT 3
- HTTP/1.1 404 Not Found : Wrong api endpoint HOT 4
- dev requirements inside main project HOT 3
- [Feature Request] Handler for message editions HOT 1
- Need to fix issue flagged when using latest Pytype HOT 2
- Websocket HOT 3
- Legal way to get raw events HOT 6
- Mandatory MATTERMOST_PORT breaks MATTERMOST_URL with subpaths HOT 2
- Disable httpx logging? HOT 2
- Reading previously sent messages HOT 1
- Bot.run does not return when stop is called HOT 3
- Bot fails to respond with copied ping if username is capitalized HOT 2
- Import plugins from separate files
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mmpy_bot.