I am using Wechaty.Grpc, sorry for did not follow the existing issue template.
I made a test with Wechaty.Grpc and donut token, I got the wrong message type from donut.
Here is the complete code:
class Program
{
static async System.Threading.Tasks.Task Main(string[] args)
{
Console.WriteLine("Hello World!");
var url = @"https://api.chatie.io/v0/hosties/" + "puppet_donut_xxxxxx";
HostieEndPoint model = new HostieEndPoint();
using (var client = new HttpClient())
{
var response = client.GetAsync(url).Result;
if (response.StatusCode == System.Net.HttpStatusCode.OK)
{
model = JsonConvert.DeserializeObject<HostieEndPoint>(await response.Content.ReadAsStringAsync());
}
}
string endPoint = model.IP + ":" + model.Port;
// 方式一
endPoint = "http://" + model.IP + ":" + model.Port;
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true);
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2Support", true);
// 方式一
var channel = Grpc.Net.Client.GrpcChannel.ForAddress(endPoint);
//var channel = new Channel(endPoint, ChannelCredentials.Insecure);
var grpcClient = new PuppetClient(channel);
try
{
var version = grpcClient.Version(new VersionRequest()).Version;
//var resonse = grpcClient.Ding(new DingRequest() { Data = "ding" });
//await channel.ShutdownAsync();
}
catch (Exception ex)
{
}
var ministring = "";
var eventStream = grpcClient.Event(new EventRequest());
var stream = Task.Run(async () =>
{
await foreach (var resp in eventStream.ResponseStream.ReadAllAsync())
{
EventType eventType = resp.Type;
string payload = resp.Payload;
if (eventType == EventType.Scan)
{
var eventData = JsonConvert.DeserializeObject<EventScanPayload>(payload);
string qrcodeImageUrl = "https://wechaty.github.io/qrcode/" + eventData.Qrcode;
Console.WriteLine($"onScan {eventData.Status},qrCodeUrl:{qrcodeImageUrl}");
Url generator = new Url(qrcodeImageUrl);
QRCodeGenerator qrGenerator = new QRCodeGenerator();
QRCodeData qrCodeData = qrGenerator.CreateQrCode(payload, QRCodeGenerator.ECCLevel.L);
AsciiQRCode qrCodeAsi = new AsciiQRCode(qrCodeData);
string qrCodeAsAsciiArt = qrCodeAsi.GetGraphic(1);
Console.WriteLine(qrCodeAsAsciiArt);
}
else if (eventType == EventType.Message)
{
var message = JsonConvert.DeserializeObject<EventMessagePayload>(payload);
var request = new MessagePayloadRequest()
{
Id = message.MessageId
};
var response = await grpcClient.MessagePayloadAsync(request);
//by checking the message type response.Type, here are test result
//received message type message type from response.Type
// MINI LOCATION
// TEXT VIDEO
//LOCATION CHATHISTORY
}
}
});
await grpcClient.StartAsync(new StartRequest());
Console.ReadKey();
}
public partial class EventMessagePayload
{
[JsonProperty("messageId")]
public string MessageId { get; set; }
}
public partial class MessagePayload
{
[JsonProperty("filename", Required = Required.DisallowNull, NullValueHandling = NullValueHandling.Ignore)]
public string Filename { get; set; }
[JsonProperty("id", Required = Required.Always)]
public string Id { get; set; }
[JsonProperty("text", Required = Required.DisallowNull, NullValueHandling = NullValueHandling.Ignore)]
public string Text { get; set; }
[JsonProperty("timestamp", Required = Required.Always)]
public double Timestamp { get; set; }
[JsonProperty("type", Required = Required.Always)]
public MessageType Type { get; set; }
[JsonProperty("fromId", Required = Required.DisallowNull, NullValueHandling = NullValueHandling.Ignore)]
public string FromId { get; set; }
[JsonProperty("mentionIdList", Required = Required.DisallowNull, NullValueHandling = NullValueHandling.Ignore)]
public List<string> MentionIdList { get; set; }
[JsonProperty("roomId", Required = Required.DisallowNull, NullValueHandling = NullValueHandling.Ignore)]
public string RoomId { get; set; }
[JsonProperty("toId", Required = Required.DisallowNull, NullValueHandling = NullValueHandling.Ignore)]
public string ToId { get; set; }
}
public partial class EventScanPayload
{
[JsonProperty("data", Required = Required.DisallowNull, NullValueHandling = NullValueHandling.Ignore)]
public string Data { get; set; }
[JsonProperty("qrcode", Required = Required.DisallowNull, NullValueHandling = NullValueHandling.Ignore)]
public string Qrcode { get; set; }
[JsonProperty("status")]
public ScanStatus Status { get; set; }
}
public enum ScanStatus
{
Unknown = 0,
Cancel = 1,
Waiting = 2,
Scanned = 3,
Confirmed = 4,
Timeout = 5,
}
public class HostieEndPoint
{
public string Port { get; set; }
public string IP { get; set; }
}
}
By checking the message type from response.Type. It will return unmatched result.
If I received MiniProgram, response.Type is LOCATION,
If I received Text, response.Type is VIDEO,
If I received LOCATION , response.Type is CHATHISTORY .
I am using
Wechaty.Grpc
, sorry for did not follow the existing issue template.I made a test with
Wechaty.Grpc
and donut token, I got the wrong message type from donut.Here is the complete code:
By checking the message type from
response.Type
. It will return unmatched result. If I received MiniProgram,response.Type
is LOCATION, If I received Text,response.Type
is VIDEO, If I received LOCATION ,response.Type
is CHATHISTORY .