Send Message error 500 in Microsoft BotConnectorBot - facebook

I'm working with Bot Connector to reply message.
I using incomingMessage.CreateReplyMessage() it worked, but i new ConnectorClient() to reply then 500 Internal Server Error. Non-bots can't talk to non-bots
public async Task<Message> Post([FromBody]Message incomingMessage)
{
var connector = new ConnectorClient();
connector.Messages.SendMessage(incomingMessage.CreateReplyMessage("ねぇ"));
connector.Messages.SendMessage(incomingMessage.CreateReplyMessage("お返事ちょうだい?"));
connector.Messages.SendMessage(incomingMessage.CreateReplyMessage("なんでお返事くれないの?"));
connector.Messages.SendMessage(incomingMessage.CreateReplyMessage("どうして?"));
connector.Messages.SendMessage(incomingMessage.CreateReplyMessage("私のこと捨てるの?"));
connector.Messages.SendMessage(incomingMessage.CreateReplyMessage("ねぇ"));
connector.Messages.SendMessage(incomingMessage.CreateReplyMessage("なんで?"));
connector.Messages.SendMessage(incomingMessage.CreateReplyMessage("嘘つき"));
connector.Messages.SendMessage(incomingMessage.CreateReplyMessage("なんでこんなひどいことするの?"));
connector.Messages.SendMessage(incomingMessage.CreateReplyMessage("なんで?"));
connector.Messages.SendMessage(incomingMessage.CreateReplyMessage("なんで?なんで?なんで?なんで?なんで?なんで?なんで?なんで?なんで?なんで?なんで?なんで?なんで?なんで?なんで?なんで?なんで?なんで?"));
return incomingMessage.CreateReplyMessage("今あなたの家の前にいるの");
}

I had a same problem, but https://stackoverflow.com/a/37334528/5951301 helped me to solve it:
using (var scope = DialogModule.BeginLifetimeScope(Conversation.Container, message))
{
var client = scope.Resolve<IConnectorClient>();
client.Messages.SendMessage(message);
}

Had the same problem, and in my case it was because I was using the Bot Framework Emulator to invoke my bot logic (the Post method). The only way I got the direct connection via ConnectorClient working was to do a real end-to-end test via a configured channel (like Skype).

Try this:
var connector = new ConnectorClient(new Uri("http://localhost:9000"), new ConnectorClientCredentials());
connector.Messages.SendMessage(message.CreateReplyMessage("Simple Text"));

Related

stream two event messages in one from gRPC Server

I have a scenario where I am trying to send multiple messages in one and trying to stream the one message from the gRPC server to the gRPC client side.
My proto files on server side look like this:
Service Greeter{
rpc AccumulateEvents (EventRequest) returns (stream EventsMessage);
}
message EventsMessage{
FirstEvent firstEvents =1;
SecondEvents secondEvent = 2;
}
message EventRequest{
//sending empty request
}
The service method is as follows:
public override async Task AccumulateEvents(EventRequest eventRequest, IServerStreamWriter < EventsMessage > responseStream, ServerCallContext context) {
IDisposable disposable4 = service.SubscribeToEvents(OnEvents);
service.execute();
await responseStream.WriteAsync(new EventsMessage {
FirstEvent = firstEvent, SecondEvents = secondEvents
});
}
When I am trying to fetch and parse the stream from the client side,i am getting null for secondEvent part of the message EventsMessage. Only firstEvents was returned from the server to the client. I tried debugging and could see secondEvent getting populated but then it became null when the streaming started from the server.
Also, secondEvent is a repeated field. I am not sure if that is the reason of it becoming null.
Please let me know what i might be missing here.

SignalR Core - Error: Websocket closed with status code: 1006

I use SignalR in an Angular app. When I destroy component in Angular I also want to stop connection to the hub. I use the command:
this.hubConnection.stop();
But I get an error in Chrome console:
Websocket closed with status code: 1006
In Edge: ERROR Error: Uncaught (in promise): Error: Invocation canceled due to connection being closed. Error: Invocation canceled due to connection being closed.
It actually works and connection has been stopped, but I would like to know why I get the error.
This is how I start the hub:
this.hubConnection = new HubConnectionBuilder()
.withUrl("/matchHub")
.build();
this.hubConnection.on("MatchUpdate", (match: Match) => {
// some magic
})
this.hubConnection
.start()
.then(() => {
this.hubConnection.invoke("SendUpdates");
});
EDIT
I finally find the issue. Its caused by change streams from Mongo. If I remove the code from SendUpdates() method then OnDisconnected is triggered.
public class MatchHub : Hub
{
private readonly IMatchManager matchManager;
public MatchHub(IMatchManager matchManager)
{
this.matchManager = matchManager;
}
public async Task SendUpdates() {
using (var changeStream = matchManager.GetChangeStream()) {
while (changeStream.MoveNext()) {
var changeStreamDocument = changeStream.Current.FullDocument;
if (changeStreamDocument == null) {
changeStreamDocument = BsonSerializer.Deserialize<Match>(changeStream.Current.DocumentKey);
}
await Clients.Caller.SendAsync("MatchUpdate", changeStreamDocument);
}
}
}
public override async Task OnDisconnectedAsync(Exception exception)
{
await base.OnDisconnectedAsync(exception);
}
}
Method GetChangeStream from the manager.
ChangeStreamOptions options = new ChangeStreamOptions() { FullDocument = ChangeStreamFullDocumentOption.UpdateLookup };
var watch = mongoDb.Matches.Watch(options).ToEnumerable().GetEnumerator();
return watch;
But I don't know how to fix it.
This can be for many reasons but i think it is most likely this one:
I think this is because of how the server is handling the connected / disconnected events. I can't say for sure but the connection closing needs to handled correctly on the server also with code. Try overriding the built in On Connected /Disconnected methods on the server and see. My assumption only is that you're closing it but the server isn't closing properly and therefore not relaying the proper closed response.
found as a comment at : getting the reason why websockets closed with close code 1006
Where you don't need to change the connection/disconection because evrything works fine. But as an answer this one is the most likely.
It throws error because the callback doesn't get clear properly.
And it is caused by the return data from websocket.
normally it should return like
However, for some reason it might return something like
the very last response breaking into 2 pieces
And that causes the issue.
I don't think there is a way to bypass this without changing the source code.
I reported this on github repo as well at here
It turns out that I can just utilize invocation response to notify client to stop the hub. So it doesn't trigger racing issue.

SignalR Core with Redis Pub\Sub and console application

I am having Asp.Net Core 2.1 with SignalR Core 1.0.1.
I have created chat application that is described here:
https://learn.microsoft.com/en-us/aspnet/core/tutorials/signalr?view=aspnetcore-2.1&tabs=visual-studio
Also have configured SignalR to use Redis using
services.AddSignalR().AddRedis(Configuration["ConnectionStrings:Redis"]);
Having running Redis server up with redis-cli monitor I can see the following commands coming:
1530086417.413730 [0 127.0.0.1:57436] "SUBSCRIBE" "SignalRCore.Hubs.ChatHub:connection:VAIbFqtNyPVaod18jmm_Aw"
1530086428.181854 [0 127.0.0.1:57435] "PUBLISH" "SignalRCore.Hubs.ChatHub:all" "\x92\x90\x81\xa4json\xc4W{\"type\":1,\"target\":\"ReceiveMessage\",\"arguments\":[{\"user\":\"user\",\"message\":\"message\"}]}\x1e"
Everything works fine till the time when I would like to push some message from another console application.
In that application I am using ServiceStack.Redis and the code is the following:
var redisManager = new RedisManagerPool(configuration["ConnectionStrings:Redis"]);
using (var client = redisManager.GetClient())
{
client.PublishMessage("SignalRCore.Hubs.ChatHub:all", "{\"type\":1,\"target\":\"ReceiveMessage\",\"arguments\":[{\"user\":\"FromConsole\",\"message\":\"Message\"}]");
}
The messages are not handled by browser. I assume the case is in this additional information that is used for SignalR:
"\x92\x90\x81\xa4json\xc4W{...}\x1e"
Related monitor record:
1530087843.512083 [0 127.0.0.1:49480] "PUBLISH" "SignalRCore.Hubs.ChatHub:all" "{\"type\":1,\"target\":\"ReceiveMessage\",\"arguments\":[{\"user\":\"FromConsole\",\"message\":\"Message\"}]"
Any ideas how can I specify this additional data for publish?
Probably I should use something more suitable for my case instead of ServiceStack.Redis
using Microsoft.AspNetCore.SignalR.Protocol;
using Microsoft.AspNetCore.SignalR.Redis.Internal;
using StackExchange.Redis;
using System.Collections.Generic;
static void Main(string[] args)
{
using (var redis = ConnectionMultiplexer.Connect("127.0.0.1:6379"))
{
var sub = redis.GetSubscriber();
var protocol = new JsonHubProtocol();
var redisProtocol = new RedisProtocol(new List<JsonHubProtocol>() { protocol});
var bytes = redisProtocol.WriteInvocation("ReceiveMessage", new[] { "60344", "60344" });
sub.Publish("SignalRChat.Hubs.ChatHub:all", bytes);
}
}
How to find it?
in signalr source code search ".Publish", you can find the https://github.com/aspnet/SignalR/blob/c852bdcc332ffb998ec6a5b226e35d5e74d24009/src/Microsoft.AspNetCore.SignalR.StackExchangeRedis/RedisHubLifetimeManager.cs
it uses the RedisProtocol and messagepack to .WriteBytes. header footer name count...

Provide UserName<553> message in quick

I have created an application for FIX transactions using QuickFIX c++ API. The application is connecting to the server but the server sends "Provide UserName<553>" message. I looked for and result and found that i need to add username and password to the toAdmin method created this following code to in order to achieve that
void Application::toAdmin( FIX::Message& message, const FIX::SessionID& sessionID)
{
if (FIX::MsgType_Logon == message.getHeader().getField(FIX::FIELD::MsgType))
{
FIX44::Logon& logon_message = dynamic_cast<FIX44::Logon&>(message);
logon_message.setField(FIX::Username("my_username"));
logon_message.setField(FIX::Password("my_password"));
}
}
But then it throws and Exception. Please suggest what to do
remove this line and exception is handled
FIX44::Logon& logon_message = dynamic_cast<FIX44::Logon&>(message);
after that Put it
message.setField(FIX::Username("my_username"));
```````
message.setField(FIX::Password("my_password"));

MessageQueue Quirks while Sending Messages

Writing to remote MSMQ seems to be working on/off. I am not sure what is wrong and what else to do to confirm sending.
I am reluctant to setup some kind of ack. It seems to be an overkill.
using (var queue = new MessageQueue(queueName, QueueAccessMode.Send))
{
var messageQueueTransaction = new MessageQueueTransaction();
messageQueueTransaction.Begin();
try
{
queue.Formatter = new XmlMessageFormatter(new Type[] { typeof(EmailMessage) });
var msg = new Message();
msg.Label = emailMessage.Subject;
msg.Body = emailMessage;
queue.Send(msg, messageQueueTransaction);
messageQueueTransaction.Commit();
}
catch (Exception e)
{
LoggerLib.Logger.ErrorException(e, "Error Sending Email using MSMQ", emailMessage);
messageQueueTransaction.Abort();
}
finally
{
queue.Close();
}
}
The Connection string for MSMQ is in the format of:"FormatName:DIRECT=OS:FULLMACHINENAME\private$\emailmessagequeue"
Also, I used "FormatName:DIRECT:TCP:IPAddress\private$\emailmessagequeue".
It works without a glitch when I ran it locally. So, I allowed Everyone to have Full access and It still doesn't work.
Any ideas?
The port number 1801 was blocked. That resolved it. –