Skip to content

实际使用中遇到的问题的一些修改,经过测试。 #29

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 1 commit into from
Aug 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 56 additions & 14 deletions src/Wechaty/Wechaty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -475,29 +475,71 @@ public ContactSelf UserSelf()
throw new NotImplementedException();
}

public Task<Message> Say(string text, params Contact[]? replyTo)
public async Task<Message?> Say(string text, params Contact[]? replyTo)
{
throw new NotImplementedException();
var msgId = await Puppet.MessageSendText(Id, text, replyTo?.Select(c => c.Id));
if (msgId != null)
{
var result = WechatyInstance.Message.Load(msgId);
await result.Ready;
return result;
}
return null;
}

public Task<Message> Say(Contact contact, params Contact[]? replyTo)
public async Task<Message?> Say(Message message)
{
throw new NotImplementedException();
var msgId = await Puppet.MessageForward(Id, message.Id);
if (msgId != null)
{
var result = WechatyInstance.Message.Load(msgId);
await result.Ready;
return result;
}
return null;
}

public Task<Message> Say(FileBox fileBox, params Contact[]? replyTo)
public async Task<Message?> Say(string id, Contact contact)
{
throw new NotImplementedException();
var msgId = await Puppet.MessageSendContact(id, contact.Id);
if (msgId != null)
{
var result = WechatyInstance.Message.Load(msgId);
await result.Ready;
return result;
}
return null;
}

public Task<Message> Say(MiniProgram miniProgram, params Contact[]? replyTo)
public async Task<Message?> Say(string id,FileBox fileBox)
{
throw new NotImplementedException();
var msgId = await Puppet.MessageSendFile(id, fileBox);
if (msgId != null)
{
var result = WechatyInstance.Message.Load(msgId);
await result.Ready;
return result;
}
return null;
}

public Task<Message> Say(UrlLink urlLink, params Contact[]? replyTo)
public async Task<Message?> Say(string id,UrlLink urlLink)
{
throw new NotImplementedException();
var msgId = await Puppet.MessageSendUrl(id, urlLink.Payload);
if (msgId != null)
{
var result = WechatyInstance.Message.Load(msgId);
await result.Ready;
return result;
}
return null;
}
public async Task<Message?> Say(string id, MiniProgram miniProgram)
{
var msgId = await Puppet.MessageSendMiniProgram(id, miniProgram.Payload);
if (msgId != null)
{
var result = WechatyInstance.Message.Load(msgId);
await result.Ready;
return result;
}
return null;
}

public void Ding()
Expand Down
2 changes: 2 additions & 0 deletions src/modules/Wechaty.Module.Puppet/WechatyPuppet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis;
using Microsoft.Extensions.Logging;
Expand Down Expand Up @@ -611,6 +612,7 @@ public async Task SetFriendshipPayload(string friendshipId, FriendshipPayload ne
public abstract Task<string> MessageContact(string messageId);
public abstract Task<FileBox> MessageFile(string messageId);
public abstract Task<FileBox> MessageImage(string messageId, ImageType imageType);
public abstract Task<byte[]> MessageImageStream(string messageId, ImageType imageType, CancellationToken cancellationToken);
public abstract Task<MiniProgramPayload> MessageMiniProgram(string messageId);
public abstract Task<UrlLinkPayload> MessageUrl(string messageId);

Expand Down
19 changes: 19 additions & 0 deletions src/modules/Wechaty.Module.PuppetService/GrpcPuppet.Message.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using github.wechaty.grpc.puppet;
using Newtonsoft.Json;
Expand Down Expand Up @@ -47,6 +48,24 @@ public override async Task<FileBox> MessageImage(string messageId, Puppet.Schema
return FileBox.FromJson(fileBox);
}

public override async Task<byte[]> MessageImageStream(string messageId, Puppet.Schemas.ImageType imageType, CancellationToken cancellationToken = default)
{
var request = new MessageImageStreamRequest
{
Id = messageId,
Type = (github.wechaty.grpc.puppet.ImageType)imageType
};

var response = grpcClient.MessageImageStream(request);
var bytes = new List<byte>();
while (await response.ResponseStream.MoveNext(cancellationToken))
{
bytes.AddRange(response.ResponseStream.Current.FileBoxChunk.Data.ToByteArray());
}

return bytes.ToArray();
}

public override async Task<MiniProgramPayload> MessageMiniProgram(string messageId)
{
var request = new MessageMiniProgramRequest
Expand Down