Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require('../vendor/autoload.php');
- $app = new Silex\Application();
- $app['debug'] = true;
- // Register the monolog logging service
- $app->register(new Silex\Provider\MonologServiceProvider(), array(
- 'monolog.logfile' => 'php://stderr',
- ));
- // Register view rendering
- $app->register(new Silex\Provider\TwigServiceProvider(), array(
- 'twig.path' => __DIR__.'/views',
- ));
- // Our web handlers
- $app->get('/', function() use($app) {
- return 'VK Bot';
- });
- $app->post('/bot', function() use($app) {
- $data = json_decode(file_get_contents('php://input'));
- if (!$data)
- return 'No data';
- $count = json_decode( file_get_contents('https://api.vk.com/method/messages.getConversations?offset=0&count=100&filter=unanswered&access_token=ACCESS_TOKEN&v=5.103'))->response->count;
- if ($data->type == 'confirmation')
- return 'CONFIRMATION_CODE';
- if ($count != 0)
- {
- $request_params = array(
- 'peer_id' => $data->object->message->from_id,
- 'random_id' => rand(1, 2147483647),
- 'message' => 'Тестирование работы PHP VK бота на Heroku',
- 'access_token' => 'ACCESS_TOKEN',
- 'v' => '5.103'
- );
- file_get_contents('https://api.vk.com/method/messages.send?' . http_build_query($request_params));
- echo 'ok';
- }
- return 'Error';
- });
- $app->run();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement