Comments (3)
Attachments are not something listened on. Any message can have an attachment.
Inside of the trigger function you need to check if the message includes any attached file.
See the example code below:
@listen_to("^handle-attachment")
def handle_attachment(self, message: Message) -> None:
try:
files = message.body["data"]["post"]["metadata"].get("files", ())
except KeyError:
logger.exception("Unexpected reply from Mattermost")
self.driver.reply_to(
message,
"An unexpected error occurred while trying to obtain the attached file. "
"The error has been logged.",
)
return
else:
if len(files) != 1:
self.driver.reply_to(
message,
"Too few or too many files attached. "
"Please attach exactly one file.",
)
return
reply = self.driver.files.get_file(files[0]["id"])
file_contents = reply.content
from mmpy_bot.
@muirdok If the above answered your question, feel free to close this issue.
from mmpy_bot.
Thanks! I'll try it.
from mmpy_bot.
Related Issues (20)
- Click help text formatting sugestion HOT 4
- Duplicate content in click command help output HOT 1
- Two Traceback errors finded HOT 8
- 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
- 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
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.