M
M
Mikhail2017-02-03 14:02:37
PHP
Mikhail, 2017-02-03 14:02:37

PHP correct use of namespace, how to connect Telegram Bot SDK?

Hello!
I can’t connect and use the Telegram Bot SDK
in any way I can’t make the example work

use Telegram\Bot\Api;
$telegram = new Api('BOT TOKEN');
$response = $telegram->setWebhook(['url' => 'https://example.com/<token>/webhook']);

I get an error about an unknown class, if I include it, that is, I write:
require_once ('./Api.php');
use Telegram\Bot\Api;
$telegram = new Api('BOT TOKEN');
$response = $telegram->setWebhook(['url' => 'https://example.com/<token>/webhook']);

Then the class is loaded, but the error is already happening in it, it does not find the class - Fatal error: Trait 'Telegram\Bot\Events\EmitsEvents' not found in /home/user/public_html/some_dir/Api.php
What did not do with this class (Api .php) didn’t lead to anything, and there can’t be an error in it, I should have an error, and since I didn’t work with the namespace before, I think that there may be an error in not understanding how to correctly connect the Telegram API from my script .
I’ve been suffering for half a day with connecting this API, I’m starting to think that it will be faster to write the functionality for those functions that I need myself, but I don’t want to just quit using the API and write my own implementation when there is a ready-made solution.
I would really appreciate your help, thanks!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexey Rudkovsky, 2017-02-03
@NeiroNext

First do
Then in your file

<?php
require __DIR__.'/vendor/autoload.php';

and then use as tried
use Telegram\Bot\Api;
$telegram = new Api('BOT TOKEN');
$response = $telegram->setWebhook(['url' => 'https://example.com/<token>/webhook']);

K
kpa6uu, 2017-02-03
@kpa6uu

https://telegram-bot-sdk.readme.io/docs/getting-started
There the composer should generate autoload. You need to connect it and everything will be zer-good.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question