Comments (8)
Hi,
sure, have you tried this?
upload a file (FileModel -> uploadFile)
create a post (PostModel -> createPost)
from php-mattermost-driver.
I haven't tried.
I guess it's not possible with your project?
from php-mattermost-driver.
Of course it's possible, this client works with all the mattermost endpoints. You simply need to work with the related Model.
Here is the list of the models supported.
For example to work with files:
$fileModel = $driver->getFileModel();
In your case you have to do something like this to upload a file:
$result = $driver->getFileModel()->uploadFile([
//..
]);
and then use the PostModel to send a post with the file.
Anyway thanks to you I realized that the upload file method is missing 2 parameters, I'll fix it now.
Thanks!
from php-mattermost-driver.
Sorry, everythings fine, it should be enough to do:
$result = $driver->getFileModel()->uploadFile([
'channel_id' => 'The ID of the channel that this file will be uploaded to',
'filename' => 'The name of the file to be uploaded',
'files' => 'A file to be uploaded',
]);
and then
$result = $driver->getPostModel()->createPost([
'channel_id' => 'The channel ID to post in',
'messages' => 'The message contents, can be formatted with Markdown',
'file_ids' => 'A list of file IDs to associate with the post',
]);
from php-mattermost-driver.
Really, you're great! Thank you for helping.
Can you show a sample code in the README.md file? I believe that this will help other people.
from php-mattermost-driver.
Sure, I think it's useful, thanks for your suggestion!
Done :)
from php-mattermost-driver.
Hi. In the createpost syntax, i had to use 'message' instead of 'messages'.
Here is my working example:
`function upload_and_post_mm ($channel_id,$filename,$files,$messages) {
include "../includes/mattermost-driver.php";
//Upload a file
$result = $driver->getFileModel()->uploadFile([
'channel_id' => $channel_id, /* 'The ID of the channel that this file will be uploaded to' */
'filename' => $filename, /* 'The name of the file to be uploaded' */
'files' => fopen($files, 'rb'), /* 'Path of the file to be uploaded' */
]);
$data = (array)json_decode($result->getBody(), true); // returns an array
$file_ids = $data['file_infos'][0]['id'];
//Send a post with the file just uploaded
$result = $driver->getPostModel()->createPost([
'channel_id' => $channel_id, /* 'The channel ID to post in' */
'message' => $messages, /* 'The message contents, can be formatted with Markdown' */
'file_ids' => [$file_ids], /* 'A list of file IDs to associate with the post' */
]);
//Please read the FileModel class or refer to the api documentation for a complete list of available methods.
}
`
from php-mattermost-driver.
Hi @rkeuter,
great! Many thanks for pointed that out, I've fixed the README!
from php-mattermost-driver.
Related Issues (20)
- Join forces on MattermostAPI client? HOT 3
- " Class 'Pimple\Container' not found" HOT 1
- Can not upload file HOT 7
- Can't use search in channel ! HOT 6
- Methods to manage icons HOT 4
- Returns 500 HOT 4
- Laravel 7 support? HOT 2
- Preferences model are locked to single user because of model caching HOT 7
- Support limit_after and limit_before parameters in request to get posts around oldest unread HOT 3
- With https:// in the beginning 500 error and without nothing happens HOT 5
- Laravel 7 Support HOT 2
- guzzle 7.x support HOT 1
- Missing Endpoints in ReactionModel? HOT 2
- Endpoint for custom user status HOT 1
- Fatal error: Declaration of Illuminate HOT 8
- Guzzle HOT 2
- Decouple from Pimple HOT 5
- Add optional permanent=true to user and channel delete HOT 1
- Api function
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 php-mattermost-driver.