Продолжая свои эксперименты с “умным” домом, ради забавы я решил добавить группу в Вк для управления некоторыми его характеристиками. Для данной статьи конкретизируем задачу: попробуем написать на языке с# простого бота, который будет отвечать от имени сообщества в вк, и рассмотрим, как быстро его запустить на arm32 (в моем случае на orange pi zero).
https://oauth.vk.com/authorize?client_id=YOURAPPID&group_ids=YOURGROUPID6&display=page&scope=messages,wall,manage&response_type=token&v=5.92
https://oauth.vk.com/blank.html#expires_in=0&access_token_YOURGROUPID=YOURTOKEN
var api = new VkApi();
api.Authorize(new ApiAuthParams(){AccessToken =MyAppToken });
while (true)
{
var s = api.Groups.GetLongPollServer(MyGroupId);
var poll = api.Groups.GetBotsLongPollHistory(
new BotsLongPollHistoryParams()
{Server = s.Server, Ts = s.Ts, Key = s.Key, Wait = 1});
}
if(poll?.Updates== null) continue;
foreach (var a in poll.Updates)
{
if (a.Type == GroupUpdateType.MessageNew)
{
Console.WriteLine(a.Message.Body);
}
}
api.Messages.Send(new MessagesSendParams()
{
UserId = a.Message.UserId,
Message = a.Message.Body
});
class Program
{
public static string MyAppToken =>
"f6bf5e26*************************************************************";
public static ulong MyGroupId => 10******;
static void Main(string[] args)
{
var api = new VkApi();
api.Authorize(new ApiAuthParams(){AccessToken =MyAppToken });
while (true)
{
var s = api.Groups.GetLongPollServer(MyGroupId);
var poll = api.Groups.GetBotsLongPollHistory(
new BotsLongPollHistoryParams()
{Server = s.Server, Ts = s.Ts, Key = s.Key, Wait = 1});
if(poll?.Updates== null) continue;
foreach (var a in poll.Updates)
{
if (a.Type == GroupUpdateType.MessageNew)
{
Console.WriteLine(a.Message.Body);
api.Messages.Send(new MessagesSendParams()
{
UserId = a.Message.UserId,
Message = a.Message.Body
});
}
}
}
}
}
dotnet publish . -r linux-arm
chmod +x ConsoleApp1
./ConsoleApp1
К сожалению, не доступен сервер mySQL