Issues (8)

examples/file.php (2 issues)

1
<?php
2
/*
3
 * Example that downloads media files sent by user and replies with the default media file
4
 */
5
6
require __DIR__ . '/../vendor/autoload.php';
7
8
use erjanmx\nambaone\Client;
9
use erjanmx\nambaone\Message;
10
use erjanmx\nambaone\ClientException;
11
12
$API_KEY = '';
13
try {
14
    $client = new Client($API_KEY);
15
16
    $token = $client->api->uploadFile('PATH_TO_IMAGE');
17
18
    $media = new Message($client);
19
    $media->setType(Message::CONTENT_TYPE_MEDIA_IMAGE);
20
    $media->setContent($token);
21
22
    $client->command('message/new', function ($message) use ($client, $media) {
23
24
        $client->to($message['chat_id'])->setType($media->getType())->send($media->getContent());
0 ignored issues
show
The method to() does not exist on erjanmx\nambaone\Client. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

24
        $client->/** @scrutinizer ignore-call */ 
25
                 to($message['chat_id'])->setType($media->getType())->send($media->getContent());
Loading history...
25
        /* or */
26
        $client->api->sendMessage($media->setChatId($message['chat_id']));
27
        
28
        // if user sent media download it
29
        if ($message['type'] != Message::CONTENT_TYPE_TEXT_PLAIN) {
30
            $file_content = $client->api->getFile($message['content']);
0 ignored issues
show
The assignment to $file_content is dead and can be removed.
Loading history...
31
        }
32
    });
33
34
    $client->handleEvents();
35
} catch (ClientException $e) {
36
    //handle exception
37
}
38