Giter VIP home page Giter VIP logo

Comments (8)

gnello avatar gnello commented on July 25, 2024

Hi,
sure, have you tried this?

upload a file (FileModel -> uploadFile)
create a post (PostModel -> createPost)

from php-mattermost-driver.

emresaracoglu avatar emresaracoglu commented on July 25, 2024

I haven't tried.
I guess it's not possible with your project?

from php-mattermost-driver.

gnello avatar gnello commented on July 25, 2024

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.

gnello avatar gnello commented on July 25, 2024

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.

emresaracoglu avatar emresaracoglu commented on July 25, 2024

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.

gnello avatar gnello commented on July 25, 2024

Sure, I think it's useful, thanks for your suggestion!
Done :)

from php-mattermost-driver.

rkeuter avatar rkeuter commented on July 25, 2024

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.

gnello avatar gnello commented on July 25, 2024

Hi @rkeuter,
great! Many thanks for pointed that out, I've fixed the README!

from php-mattermost-driver.

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.