xatkit-bot-platform / xatkit-twitter-platform

Send and receive messages from Twitter, and search or post Tweets.
Other
4 stars 1 forks source link

Get Trends with WOEID from context #7

Open nerlichman opened 5 years ago

nerlichman commented 5 years ago

Get Trends with WOEID requires an integer parameter, but when retrieving the value of a context from user input and passing that value to Twitter, that value is passed as a String not as an Integer.

That causes that the action finds no results for that WOEID, when actually there may exist some.

nerlichman commented 3 years ago

Review is needed to check if this is still happening with the new Xatkit architecture.

gdaniel commented 3 years ago

We still have some legacy of the old Xatkit engine, and by default context.getSession().get("key") returns a String. Good news is that now we are in the Java world, and it's possible to write a bot state like this:

val myState = state("MyState")
    .body(context -> {
        String parameterValue = context.getSession().get("integer_parameter");
        int parameterInt = Integer.parseInt(parameterValue);
        twitterPlatform.getTrends(context, parameterInt);
    })
    .nexst() // [...]

Based on the signature of GetTrends the woeid is defined as an integer, so Java should now enforce users to use the correct type.

(Of course this implies that the bot creator needs to make the extra effort to cast the value, but I think it's fine for now, they get type safety in return).

nerlichman commented 3 years ago

That's great! I will try it when I finish migrating the Twitter Example to the new version!