单击网页版本中的“回调”按钮后,预加载器开始旋转。在下一条消息中,我发送带有新菜单的响应,但按下的按钮不会重置。显示新的,但预加载器旋转代替已按下的。您是否需要在 API 中执行其他操作来重置它?仅发送带有新菜单的下一条消息还不够吗?
Вадим Королёв
Asked:
2024-08-09 05:26:31 +0800 CST
我正在为 VKontakte 编写一个机器人。根据来自 POST 请求的传入数据,机器人创建一个事件对象并使用它。我希望机器人在 message_event 事件期间(即按下键盘按钮时)响应该事件,以便按钮的加载指示器消失。
理论上,该指示器应该在调用messages.sendMessageEventAnswer方法时按照操作顺序消失。此方法必须接受 show_snackbar、open_link、open_app 对象之一。但我不想要这些,我希望指示器消失。我该怎么做?
switch ($type) {
case "message_new":
return new TextMessageEvent(
$object["message"]["id"],
$user_model,
$chat_of_msg,
$object["message"]["text"],
[]
);
case "message_event":
$payload = $object["payload"];
// Ответ на событие должен быть здесь
return new CallbackEvent(
$object["event_id"],
$user_model,
$chat_of_msg,
CallbackType::from($payload["type"]),
$payload["data"]
);
default:
return new UnknownEvent($user_model, $chat_of_msg);
}
qqqq
Asked:
2022-08-16 05:39:13 +0800 CST
任务是用 Python 编写一个机器人代码,当进入 VK 对话时,它会发送一个问候,但有一个特点。如果有几个用户在第 n 时间段内进来,假设是 5 秒,那么问候语将影响所有进入的人,并在一条消息中提及,而不是为每个人写,造成额外的洪水。很长时间以来,我一直在寻找如何做到这一点的解决方案,但目前我只能收集一个列表中包含的所有内容,如何在 5 秒后处理它是一个大问题。请帮忙。
我的代码看起来像这样:
invites = {}
if event.object.action == 'chat_invite_user':
invites[event.object.peer_id] = [].append(event.object.member_id)
也许甚至可以将这段代码写得更好,但这就是我现在脑子里的全部。
Дима Абдукаримов
Asked:
2022-08-07 15:47:25 +0800 CST
我需要在 VK 中获取对话中所有参与者的 ID,我尝试使用“messages.getChat”和“messages.getChatUsers”方法获取它,我收到以下错误:[27] 组授权失败:方法组身份验证不可用。请帮助提供代码
bodrovdeni
Asked:
2022-08-05 01:01:33 +0800 CST
当我尝试运行时出现错误:
Caused by:
com.vk.api.sdk.exceptions.ClientException:
Internal API server error. Wrong status code: 401.
Content:
{"error":"invalid_grant","error_description":"Code is invalid or expired."}
起初我认为代码已经失去了有效性。
我又问了一遍,问题依旧。
像这样请求:
请告诉我,我哪里做错了?
package reversbot.services;
import com.vk.api.sdk.client.TransportClient;
import com.vk.api.sdk.client.VkApiClient;
import com.vk.api.sdk.client.actors.UserActor;
import com.vk.api.sdk.exceptions.ApiException;
import com.vk.api.sdk.exceptions.ClientException;
import com.vk.api.sdk.httpclient.HttpTransportClient;
import com.vk.api.sdk.objects.UserAuthResponse;
import com.vk.api.sdk.objects.wall.GetFilter;
import com.vk.api.sdk.objects.wall.responses.GetResponse;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import javax.annotation.PostConstruct;
@Service
public class VkBot {
@Value("${APP_ID}")
int APP_ID;
@Value("${CLIENT_SECRET}")
String CLIENT_SECRET;
@Value("${REDIRECT_URI}")
String REDIRECT_URI;
@Value("${code}")
String code;
@Scheduled(fixedDelay = 5000)
@PostConstruct
public void vkb() throws ClientException, ApiException {
TransportClient transportClient = new HttpTransportClient();
VkApiClient vk = new VkApiClient(transportClient);
UserAuthResponse authResponse = vk.oAuth()
.userAuthorizationCodeFlow(APP_ID, CLIENT_SECRET, REDIRECT_URI, code)
.execute();
UserActor actor = new UserActor(authResponse.getUserId(), authResponse.getAccessToken());
GetResponse getResponse = vk.wall().get(actor)
.ownerId(1)
.count(100)
.offset(5)
.filter(GetFilter.valueOf("all"))
.execute();
}
}