How can I react to a message with a pub/sub bot - hangouts-chat

I have created a Card with a button and a onClick action that successfully sends a message to my client with type "CARD_CLICKED".
When I try to respond to this message with either a type "NEW_MESSAGE" or "UPDATE_MESSAGE" message, this is displayed as a new message, while the API tries for three times to send that CARD_CLICKED event to my bot until it gives up with the visual error: "Unable to contact [bot]. Try again later."
I guess this is similar to
Interactive button doesn't work properly when using pub/sub
Interactive cards hangout chat Api
but I am using a golang client and the answer to these questions didn't help me...
My code to respond to the "CARD_CLICKED" message:
func handleClick(message *chat.DeprecatedEvent) *chat.Message {
log.Debugf("User %s instructed me to execute %s", message.User.DisplayName, message.Action.ActionMethodName)
response := &chat.Message{
ActionResponse: &chat.ActionResponse{Type: "UPDATE_MESSAGE"},
Thread: &chat.Thread{Name: message.Message.Thread.Name},
Space: &chat.Space{Name: message.Message.Space.Name, Type: message.Message.Space.Type},
Text: "CARD CLICKED!",
}
return response
}
My code is based on this project: https://github.com/jforman/hangbot

Found out what the main issue was... I was calling the .Create() function - which created a new message and thus - even though the Action Response was set correctly - this was not interpreted as a response to the click event:
https://github.com/jforman/hangbot/blob/master/hangbot.go#L79
After I switched to calling .Update() - Chat would not display the "Unable to contact" message about my bot any more.
What remains is that the click event is still sent to me three times, but I'm filtering events now based on the eventTime, which works ok for now.

Related

UI Error while calling app script functions through app script API

I have written functions in the app script bound to a google sheet that validates sheet data and shows a pop up in the sheet when there is an error.
Now, I am calling same functions form API calls in a Node js application to return a validation response without interacting google sheet.
API calls are successful, function gets called but unable to initialize UI.
I just don't want to write duplicate functions for same purpose but without accessing UI.
I get an error that says Script error message: Exception: Cannot call SpreadsheetApp.getUi() from this context.
How do I solve this issue by retaining the UI calling functionality of the app script functions and also getting work done through API?
You can put the call in a try catch block.
try {
SpreadsheetApp.getUi();
} catch (f) {
// do nothing here
}

Malformed calls from JS : field sizes are different

I've gone through link : https://github.com/facebook/react-native/issues/23835#issuecomment-493007479
But got no solution. I got the understanding that this bug is triggered when
You send NaN in array on react native bridge. I don't know much about it.
During use of invalid data (infinity) in animation.
During bottom navigation.
Using menu.
Showing response data in Alert or Notifications as Toasts.
I am using react-native-ble-manager.
Procedure: I sent write message using characteristic that allows write, after setting notifications on for characteristic that allows read. I got 'ack' in the response listener that was used to receive notifications, and then I start sending custom data chunks by chunks as designed.
I get this error during this first chunk was being sent.
I've checked my uint8Array for any wrong data using iteration and to, but couldn't found any.
From my logs:
2020-09-04 12:52:13.944 21942-22004/com.my_app E/ReactNativeJS: Error: Exception in HostFunction: Malformed calls from JS: field sizes are different.
[[3,13,37],[5,22,0],[["{\"type\":\"log\",\"level\":\"log\",\"data\":[\"payload[18]: \\u0000\"]}",1],[221,100,1599204133919,false]],2453]
I iterated through my uint8Array and took each of the elements in
var newArr = [];
I also did newArr[i] = newArr[i] & 0xff.
The error was gone.

Event "formSubmission" doesn't trigger on Circuit SDK

Circuit client in my app subscribed to event 'formSubmission':
client.addEventListener('formSubmission', function (event)
Until last days it works fine, but now it doesn't trigger.
I tried to test it by creating a simple app that just send a form (just one button on it) as a reply to user's message and should log form submissions, but it doesn't go on this function.
client.addEventListener('formSubmission', function (event) {
var submittedValue = event.form.data[0].value;
console.log(`[CIRCUIT]: Form was submitted.`);
};
Any other events like 'itemAdded' or 'itemUpdated' work as they should
Yes, just confirmed this is a bug and is being worked on. Will post here when its resolved. Are you using the circuitsandbox.net or production?
Production systems have been updated and the formSubmission event is received again. circuitsandbox will be updated with this fix soon.

Passing partial parameter in a push notification on Windows Phone 8.1

I'm trying to send a toast notification with a parameter to a Windows Phone 8.1 device, so when a user taps on the toast the app will show a particular page within the app, as it described in this MSDN article https://msdn.microsoft.com/library/windows/apps/jj662938(v=vs.105).aspx
This is a snippet that I use to add a parameter:
<wp:Param>?cmd=command1 </wp:Param>
this how I read it in the app:
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e){
base.OnNavigatedTo(e);
string strVal1 = this.NavigationContext.QueryString["cmd"];
}
After making these changes it works correctly, but only for this first notification. In all subsequent notifications the value of the parameter read within the app is same as it was in the first notification, no matter what I've sent from the server.
Here is an example:
I'm sending a notification to device that has with this parameter in the notification payload: <wp:Param>?cmd=command1 </wp:Param> The value in this.NavigationContext.QueryString("cmd") is command1, as it should be.
Then I send a second notification with this parameter parameter
<wp:Param>?cmd=command2 </wp:Param>
the cmd's value in the this.NavigationContext.QueryString("cmd") is still returned as "command1" instead of command2 as it should be. And it works like that for all subsequent notifications until I force-restart the app.
Here is what I've tried:
Checked the Uri value in the NavigationEventArgs argument of the OnNavigatedTo event and it's same as what I see in the NavigationContext.
Double checked notification payload sent from the server (it's correct)
Checked msdn/stackoverflow/google.
Checked on both 8.1 emulator and the device (it works the same)
Questions:
Do I have to do something in the app (idk, clear NavigationContext or something), so it will be different for the next notification?
Does anyone actually has a live-app that uses partial arguments (not server-driven navigation with full url, but a partial url passed to the app + corresponding navigation from within the app) and it works for multiple subsequent notifications?
Figured out what the problem was. Two OnNavigated events are fired when app is relaunched. First one has a type of System.Windows.Navigation.NavigationMode.Reset and it has the data of the old page being reset (in my case, with the data from old notification). The second one is System.Windows.Navigation.NavigationMode.New and has the data from the new notification.
A simple check of navigation mode to make sure it's of the type .New fixed the issue:
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e){
base.OnNavigatedTo(e);
if (e.NavigationMode == System.Windows.Navigation.NavigationMode.New)){
// custom navigation logic based on the data within <wp:Param/>
}
}

WinJS app with an uncatchable crash

I have random crashes in my WinJS application when navigating between pages.
The problem is that these crashes never occurs when the app is attached to the Visual Studio debugger; so I can't find where they come from.
I use the WinJS.Application.onerror event to prevent crashes, and log what happens, but as this works well when I try with a random exception, my "uncatchable" crashes doesn't seem to fire this event (I don't have anything logged).
Do you have any idea of what could cause these crashes, or any solution to find more informations ?
Sometimes errors can't fire the WinJS.Application.onerror for several reasons (in my app, the problem was in an iframe, in a page not using winjs).
When it happens, errors can be found in the event log, under "administrative events"
Found this on this link :
http://www.davepaquette.com/archive/2012/09/15/windows-8-store-app-crash-logs.aspx
Jason gives a good solution to this problem in this video (start at time 14:48). In his example, the app was crashing if you had a callback and navigated to a different page before the callback completed. Could this be the case for your app? Any more details on what is going on when you navigate?
For others (since it seems you already know about this!):
To be able to debug easier, use the WinJS.Application.OnError event. Wire up an event handler that dumps out information about the problem before the app crashes.
WinJS.Application.onerror = function (info) {
var err = {
errorMessage: info.detail.errorMessage,
errorUrl: info.detail.errorUrl,
errorLine: info.detail.errorLine,
errorCharacter: info.detail.errorCharacter,
};
Windows.Storage.ApplicationData.current.localFolder
.createFileAsync("crash.txt", Windows.Storage.CreationCollisionOption.openIfExists)
.then(function (file) {
Windows.Storage.FileIO.appendLinesAsync(file, [JSON.stringify(err)]);
});
};
The final stop for exceptions in JavaScript is actually window.onerror; not every exception will get thrown through WinJS.Application.onerror. Try hooking window.onerror directly.