ask(Alexa Skill Kit) cli asks for authorization code all the time - alexa-skills-kit

My requirement is to automate skill create and ask deploy via pipelines for which I am relying on ask cli
I am using this doc to set the envionment variables and using curl to get the access token which I then set as "ASK_ACCESS_TOKEN".
I am also aware that to get the refreshtoken, you need to provide the "Authorization code" via cli "ask generate-lwa-token --no-browser" command.
The refresh token is valid for 1 hour and I provide this refresh token as an input to my pipeline each time it gets expired.
However what I am noticing is that the refresh token even though it is expected to be valid for an hour, throws a 400 bad request the SECOND time I run the pipeline.
If I generate a new refresh token and input it, all works fine?

Related

telegram use schedule message

I want to schedule a telegram bot message to be sent at a specific unixtime.
As from telegrams official api (https://core.telegram.org/api/scheduled-messages) that should be possible by setting the schedule_date flag.
To schedule a message, simply provide a future unixtime in the schedule_date flag of messages.sendMessage or messages.sendMedia.
However I was not able to set that flag. To be more precisely, I do not even know how to set a flag, or if I am using the correct api.
What I have tried is to use the api directly via the browser (could use curl as well) like so: https://api.telegram.org/botBOT:TOKEN/sendMessage?chat_id=ID&text=Test&schedule_date=1653503351
I also did not find any way to access this flag via https://pypi.org/project/pyTelegramBotAPI/#description https://telepot.readthedocs.io/en/latest/#send-a-message, nor https://github.com/nickoala/telepot.
I want to implement this feature in a python environment, but any working suggestion would be much appreciated.
EDIT:
I decided to save the intention to send a telegram bot message at a certain unixtime in a database. I then create an infinite loop that checks if there are any unsent messages before the current timestamp. If the loop detects such a message it sends the message and sets a flag, that that message has been sent.
And as promised, here is a fully dockerized example of that behaviour in action: https://github.com/Sokrates1989/nameTheCountDown-lightweight
It creates a bot that you can pass a name and the duration. Once the duration has passed it sends a message with the passed name. Basically a simple countdown that you can give several names, that run simltaniously. As it is a telegram chat, you can modify the way you are informed about the end of a countdown by modifying the notificaiton of that chat.
And here is the Bot in action: http://t.me/NameTheCountdownBot
We can't do this by bot API itself, and there's no schedule_date parameter in sendMessage method:
https://core.telegram.org/bots/api#sendmessage
And what you've read is for Telegram clients, not bot API consumers.
If you don't really need unixtime, you can simply create a table for scheduled messages with a text, chat_id and a publish_time column (like 22:15), and run a command every minute to look if there's a message for current time to send. Then send the message and delete the record.
Note that the python-telegram-bot library has a built-in solution for scheduling tasks: The JobQueue. This feature is based on the APScheduler library, which you can ofc also use without python-telegram-bot.
Disclaimer: I'm currently the maintainer of python-telegram-bot.
https://core.telegram.org/method/messages.sendScheduledMessages
Now you can send scheduled messages right away

PasswordSignInAsync - Failing when calling this programmatically?

Please help, I want to test a service method - and during this testing I want to forcefully log-in a user by providing the user name and password - this will not be used for production, simply for a test I am conducting. But when I get the sign in manager and call the PasswordSignInAsync I receive a strange error, this error is not generated when going via Login.cshtml.cs code which reads the same?

AB testing config applied but firebase console show 0 users

I've configured firebase ab-testing. Everything works fine except there is no impact user on console.
Actually, I can see UI and log show ab-testing is applied.
Moreover, by checking the other StackoverFlow topic, activateFetched also invoked after fetch successfully.
Moreover, I've referenced
Firebase Remote Config A/B testing shows no results after 24 hours
Firebase Remote Config results on initial request
Remote Config A/B Test does not provide results on iOS
But those are no work on my case.
Is there anything miss or any other need to check so that client can response AB testing result to firebase console.
Thanks for your help first.
Code snippet:
[FIRApp configure];
FIRRemoteConfigSettings* configSettings = [[remoteConfig configSettings] initWithDeveloperModeEnabled:YES];
[[FIRRemoteConfig remoteConfig] setConfigSettings:configSettings];
[[FIRRemoteConfig remoteConfig] fetchWithExpirationDuration:duration completionHandler:^(FIRRemoteConfigFetchStatus status, NSError *error) {
if (status == FIRRemoteConfigFetchStatusSuccess) {
BOOL configFound = [[FIRRemoteConfig remoteConfig] activateFetched];
A couple things to check or take note of:
Make sure you're using and have deployed the latest Remote Config SDK. Earlier versions don't work with A/B test experiments.
Be sure to verify your experiment on a test device by following the documentation here
It can take a couple days for data to come in for your experiment.
Please call the functions in the following order:
fetch()
Call activatefetched() in the completion handler of fetch().
Fire activation event. If you need to call activation event immediately after activatefetched(), add a time delay of a few seconds. This is because activatefetched() process asynchronously and hence the function may not execute completely, before the activation event is fired.
Once done, test a running experiment on test device. In the debug logs search with string "exp_X" where 'X' is the experiment Id. You will find the experiment Id in the URL of the experiment. If you find the experiment ID in the debug logs while executing the code on test device, it means the device was covered in experiment.
Also if the experiment setup is correct, the running experiment will show 1 active experiment user in the console.

Unexpected behavior when refreshing token of a user who is the unique member of a device group

I implemented the mapping between devices, registration ids, and groups as explained here
Basically came up with a table where to store the device reg id and the notification key of the group to which it is registered (if any) , and added to my user table two fields to keep track of the number of devices that user has logged into and what is his pre determined group name.
Unfortunately, while testing, I incurred into a very strange behavior when refreshing the token of a user, who is also the only member of a device group.
as explained in the comments to the question i asked here
if the previous token was the only member of a device group, after getting refreshed it is invalidated but the group keeps existing and somehow the new token gets added to it. i can even successfully remove the new token from the group thus deleting it, or i can notify the group "waking it up" and making it to auto remove itself
in the couple of tries i have done right now before posting this is what happened:
get a new token say reg_id1
register reg_id1 to device group test_group (creating it)
code to create group:
curl --header "Authorization: your_key"
--header Content-Type:"application/json"
-H "project_id:your_id" https://android.googleapis.com/gcm/notification
-d "{ \"operation\": \"create\", \"notification_key_name\":
\"test_group\", \"registration_ids\": [\"reg_id1\" ] }"
test that the group exists
with this
curl -v -H "Content-Type:application/json" -H "Authorization:key=your_key"
-H "project_id:your_id"
https://android.googleapis.com/gcm/notification?notification_key_name=test_group
refresh reg_id1 with the way you prefer (deleting app data if on android or requesting new token if on web app )
check what happened to the group with the command at point 3
the group still exists (even if the only token there is now invalid)
try deleting old token. what should happen? well, the answer is reasonable..the token we are trying to remove is not valid anymore
code to remove
curl --header "Authorization: key=your_key"
--header Content-Type:"application/json" -H "project_id:your_id"
https://android.googleapis.com/gcm/notification
-d "{ \"operation\": \"remove\", \"notification_key_name\":
\"test_group\", \"notification_key\": \"group_key\",
\"registration_ids\": [\"reg_id1\" ] }"
Here comes the fun: try deleting the new refreshed token from the same group ! you will get a notification key in return , meaning that there were no errors..but wait ! how could it be?
ping the group again with command at point 3 and.. the group still exists?! (previously, at the time of the problem in original question, while removing the new token from android, the group would cease to exist after this point..now with curl it continues living)
try notifying the group then!
code
curl -X POST -H "your_key"
-H "Content-Type: application/json"
-d '{
"notification": {
"title": "Portugal vs. Denmark",
"body": "5 to 1",
"icon": "firebase-logo.png",
"click_action": "http://localhost:8081"
},
"to": "group_key"
}' "https://fcm.googleapis.com/fcm/send"
what happens now is that you get 1 failure (which is ok) and if you try to ping the group again it will be magically disappeared..
Sorry for being so long but i wanted to write all the steps so that you can reproduce the behavior easily.
Can someone explain all of this?
In my android app if the user deletes app data he will need to login again, since the creation/add to a device group is upon login, i need to delete the old token from the group (and delete the group if it was the last) so that he will be able to re-enter the group again (or create it).
But i can't remove the old token directly because it is invalid.
still, the group continues existing even if its only member is invalid. should i just notify it to wake it up and make it delete itself?
should i remove the new token from the group as well ? (in android this would strangely lead to deleting the group)
EDIT:
after testing this morning i have a new use case:
Create group with reg_id1 subscribed to it
refresh reg_id1
recreation of group says that group exists ( i can ping it ad receive a notification key in response)
try to delete new token from group gives error 500
notification test to the group gives 0 success and 0 failure
try to remove old token from group gives back notification key (should be a positive answer)
now group doesn't exist anymore
EDIT2:
after lots and lots of testing i came to these conclusions:
refreshing a token on android application invalidates it, if it was the only member of a device group, a simple notification to that group will wake it up and make it auto delete itself.
refreshing a token on a web application does not invalidate the token, if it was the only member of a device group, notifying the group will result in a 0 success 0 failure. while being invisible the token is still registered to the group and the group will cease to exist only when the old token will be removed. in this case, even if still there the old token won't concur to the limit of 20 devices ( i successfully registered and refreshed 25 tokens to the same group).
What is needed now is a way to retrieve the old token to remove it from the group , in a web application scenario. this is crucial since a web application doesn't have a unique id therefore it can't be mapped as in android (with the android id) to the registration token, and the old token won't even appear as a failure when notifying, meaning that it's almost impossible to retrieve it after it was refreshed.
This is what i ended up doing. it's by no means elegant, and i had to compromise between what i need and what actually happens.
First of all i confirm that:
In android , when a token gets refreshed it is invalidated, therefore automatically eliminated from every group it was part of (not instantaneously, more like at the first notification or operation of add/removal on the group).
This is why a simple notification (not dry_run though) would serve as wake up for the group, meaning that if it was the last member, the group would immediately die.
Notice that even if the token gets invalidated, in the case it was the last member of the group, the group continues to exist! a notification would wake it up and kill it, but otherwise adding more devices would still work!
On a webapp instead, the behavior is much more complex because it is browser dependent (surprise?). for example in Firefox the refreshed token magically disappears, but doesn't get invalidated. meaning that if it was the only member of a group, sending a notification to that group will result in 0 success and 0 failures, only after removing that old token from the group, the group will get deleted. Subsequent adding or removal would all work, but if you didn't remove the old token, once empty the group would not delete itself and return again 0 success - 0 failures.
In chrome instead, the behavior is like in android (token invalidated etc. ).
Since i needed something working for both android and web app i thought about differentiating the web behavior by keeping track of the token upon login , putting it in a table (user_id, reg_id). at every login i would check if every token associated with the user was still valid (sending a notification to it and looking at the failures) and in case, delete it from the user group whose group name and group key i would retrieve from my user table.
This would have greatly worked, making it possible to remove ghost tokens from groups , if not for the fact that in chrome the tokens get invalidated when refreshed (android-like), meaning that sending a notification would return a failure but with different error ("invalid registration id" instead of " not registered" or something like that).
I could have further specified my functions to do their work with respect to the browser they were in , or maybe just check the error type and understand if i had to delete it from the group because it was a ghost token or just delete the line from my db because it had been invalidated.
Well, at that point i was really fed up with the poor management api of firebase's groups, therefore i chose the simplest solution: do nothing.
I concocted a powerful function, to be executed after login , that would take care of pinging a group by its name (as explained in the question's cURL commands) and either create the group if error or add to the group if a notification key was returned.
Mind that one could even directly try to create the group, and in case of error just add the device to it, same thing.
the refresh of a token would fall in those two scenarios (invalidated or ghost), meaning that the worst that could happen is the group not dying when the last member exited, too bad. ghost tokens shouldn't add up to the limit of devices per group.
Sad, but easy and working.
If anyone can see any downside to doing as described, i would love to hear about it.

How do I send a message from a web site to my local machine?

I want to send a string from a website to a local machine.
My local machine is connected into a network through a router.
Thanks You
email Id: manish.m.meshram#gmail.com
Well, that largely depends on what the receiving computer needs to do with that string.
If you only need to notify the user of this, I would suggest the easier way is to go with the net send command.
Since you are wking in ASP.net, you can use the Process and ProcessStartInfo class to launch a command like
net send YourPC "String to send"
If you need to do something more sophisticated with the string message, you could for example print it in some sort of log file and then read it from the destination machine.
If you can give more information on your needs, we'll be probably able to help you better.
Luca
I suggest you poll the webapp for messages.
For instance, let the webapp have an URL that simply returns the timestamp of the most recent message, at http://thesite.com/messages/MostRecentTimetamp.aspx
The page should return the timestamp only, in an format you can parse, for instance:
2009-08-29 14:00:00
Then, on another URL, http://thesite.com/messages/FromLastHour.aspx display the list of messages for the last N hours (or other suitable time period). This page could return one message per line, with the message timestamp at the start of the line.
For instance:
2009-08-29 13:58:20 A message
2009-08-29 13:59:30 Here's a message
2009-08-29 14:00:00 Another message
On your local machine, create a program that as often as needed reads and parses http://thesite.com/messages/MostRecentTimetamp.aspx. If the program detects that the timestamp has changed, read http://thesite.com/messages/FromLastHour.aspx and process the new messages.
Adjust the timing according to your needs.
Or even better, have an URL: http://thesite.com/messages/MoreRecentThan.aspx?timestamp=2009-08-29 13:50:00.
That returns messages that are newer than the timestamp passed in. The program on your local machine should then pass the timestamp of the most recent message it has handled.
Of course, your web site has to keep track of outgoing messages in some sort of queue. You could use a database table for this. The web app can delete old messages from this table periodically.
If you want to get fancy, you could implement this as a SOAP web service. Or you could let the URLs return the data formatted as JSON.

Resources