Home php Message Processing in CV conversation via API

Message Processing in CV conversation via API

Author

Date

Category

created a test community. In the API settings created the key with all rights. In the event settings, the Callback API has included all events. In the message settings allowed the bot in the conversation. Added the bot to the test conversation from two people + Bot himself. Run the bot through the CLI. The bot arrive all events except any events in this conversation

& lt;? php
Namespace Program;
USE \ Io \ Console;
USE \ Swoole \ http \ server;
USE \ Swoole \ http \ request;
use \ swoole \ http \ response;
Class Main.
{
  Private $ Server;
  Public Function __Construct (Array $ Args)
  {
    $ this- & gt; Server = New Server (Config :: Server_Addr, Config :: Server_Port);
    $ this- & gt; Server- & gt; ON ("START", FUNCTION (SERVER $ SERVER) {$ this- & gt; Server_start ($ Server);});
    $ this- & gt; Server- & gt; ON ("Request", Function (Request $ Request, Response $ Response) {$ this- & gt; Server_Request ($ Request, $ Response);});
    $ this- & gt; Server- & gt; start ();
  }
  Private Function Server_start (Server $ Server): void
  {
    Logger :: Log ("Running a Swoole server on http: //". Config :: Server_addr. ":". Config :: server_port);
  }
  Private Function Server_Request (Request $ Request, Response $ Response): void
  {
    $ Response- & GT; Header ("Content-Type", "Text / Plain");
    If ($ Request- & GT; Server ["Request_uri"]! = Config :: $ Requesturi)
    {
      Logger :: Log ("Invalid URI:" $ Request- & gt; Server ["Request_uri"]);
      Logger :: Log ($ Request- & GT; RawContent ());
      $ Response- & gt; End ("Wrong URI");
      Return;
    }
    $ data = json_decode ($ Request- & gt; RawContent (), True);
    if ($ Data == NULL)
    {
      Logger :: Log ("incorrect content of the request");
      Logger :: Log ($ Request- & GT; RawContent ());
      $ Response- & gt; End ("Bad Request");
      Return;
    }
    if ($ Data ["Type"] == "confirmation")
    {
      Logger :: Log ("VK sent a confirmation request");
      If (! isset ($ data ["group_id"]) || $ Data ["group_id"]! = config :: $ groupid)
      {
        Logger :: Log ("Requirement request came from another community");
        $ Response- & GT; END ("Invalid Group");
        Return;
      }
      If (! Isset ($ Data ["SECRET"]) || $ Data ["Secret"]! = config :: $ secretkey)
      {
        Logger :: Log ("Invalid confirmation key. Check that in the community settings and in the bot settings one and the same Secret Key");
        $ Response- & GT; END ("Invalid Secret Key");
        Return;
      }
      $ response- & gt; end (config :: $ confirmResponse);
      Logger :: Log ("confirmed");
      Return;
    }
    ELSE.
    {
      Logger :: Log ($ Request- & GT; RawContent ());
    }
    $ Response- & gt; End ("OK");
  }
}

Answer 1

The problem turns out all this time I had under my nose. The Callback API settings in the community management stood version 5.50. And the support of chat bots in the conversation is only with 5.80 versions.

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions