Botpress在执行代码动作形式中将变量作为参数连接起来

时间:2018-04-16 20:09:48

标签: javascript chatbot

我知道如果我在args操作字段中传递{{variable}}(如{{event.text}}),则可以正常工作。

enter image description here

但是,当我尝试将此变量与另一个String连接时,这不起作用。

enter image description here

结果是 {{state.api_url}} / users 字符串,我需要 http // myapi.com / users

有可能吗?

1 个答案:

答案 0 :(得分:1)

基于错误的javascript,我可能对此有 kludgy 解决方法。

我一直想向下迭代temp变量。我在原始代码框中做了转换

public class MyFirebaseMessagingService extends FirebaseMessagingService { private static final String TAG = MyFirebaseMessagingService.class.getSimpleName(); @Override public void onMessageReceived(RemoteMessage remoteMessage) { Log.e(TAG, "From: " + remoteMessage.getFrom()); if (remoteMessage == null) return; // Check if message contains a notification payload. if (remoteMessage.getNotification() != null) { handleNotification(remoteMessage.getNotification().getBody()); showSimpleMsg(remoteMessage.getNotification()); } // Check if message contains a data payload. if (remoteMessage.getData().size() > 0) { try { JSONObject json = new JSONObject(remoteMessage.getData()); storeNotificationToPreferences(remoteMessage.getNotification().getTitle(), remoteMessage.getNotification().getBody(), json); } catch (Exception e) { e.printStackTrace(); } } } private void showSimpleMsg(RemoteMessage.Notification notification) { Intent pushNotification = new Intent(Config.PUSH_NOTIFICATION); pushNotification.putExtra("message", notification.getBody()); LocalBroadcastManager.getInstance(this).sendBroadcast(pushNotification); showNotificationMessage(getApplicationContext(), notification.getTitle(), notification.getBody()); } private void handleNotification(String message) { if (!NotificationUtils.isAppIsInBackground(getApplicationContext())) { // app is in foreground, broadcast the push message Intent pushNotification = new Intent(Config.PUSH_NOTIFICATION); pushNotification.putExtra("message", message); LocalBroadcastManager.getInstance(this).sendBroadcast(pushNotification); // play notification sound NotificationUtils notificationUtils = new NotificationUtils(getApplicationContext()); notificationUtils.playNotificationSound(); } else { // If the app is in background, firebase itself handles the notification } } private void showNotificationMessage(Context context, String title, String message) { if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { Intent intent = new Intent(getApplicationContext(), MainActivity.class); String CHANNEL_ID = "olonce"; NotificationChannel notificationChannel = null; notificationChannel = new NotificationChannel(CHANNEL_ID, "olonce", NotificationManager.IMPORTANCE_LOW); PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), 1, intent, 0); Notification notification = new Notification.Builder(getApplicationContext(), CHANNEL_ID) .setContentText(message) .setContentTitle(title) .setContentIntent(pendingIntent) .setChannelId(CHANNEL_ID) .setSmallIcon(R.mipmap.ic_launcher) .build(); NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.createNotificationChannel(notificationChannel); notificationManager.notify(1, notification); } else { Intent intent = new Intent(getApplicationContext(), MainActivity.class); PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), 1, intent, 0); Notification notification = new Notification.Builder(getApplicationContext()) .setContentText(message) .setContentTitle(title) .setContentIntent(pendingIntent) .setSmallIcon(R.mipmap.ic_launcher) .build(); NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(1, notification); } } private void storeNotificationToPreferences(String title, String message,JSONObject extraData) { SharedPreferences preferences = getApplicationContext().getSharedPreferences("Notifications", MODE_PRIVATE); try { //Default Data JSONObject jsonObject = new JSONObject(); jsonObject.put("data", new JSONArray()); jsonObject.put("unread", 0); JSONObject oldData = new JSONObject(preferences.getString("notifications", jsonObject.toString())); JSONArray data = oldData.getJSONArray("data"); data.put(new JSONObject().put("title", title).put("message", message).put("data",extraData)); int unread = (oldData.has("unread") ? oldData.getInt("unread") : 0) + 1; oldData.put("unread", unread); SharedPreferences.Editor editor = preferences.edit(); editor.remove("notifications"); editor.putString("notifications", oldData.toString()); editor.commit(); EventBus.getDefault().post(Common.EVENTS.NOTIFICATION); } catch (JSONException e) { e.printStackTrace(); } } } 这样的好代码将是对还是错的测试。

但是仅使用一个等号即可执行赋值

因此,原始代码框中的temp.variable==1从我的(数值)变量中减去了一个。

出于过渡的目的,这似乎返回False,因此只要它在链中,指向它的位置都无所谓。

无论如何,这似乎对我有用。

我完全不确定您的代码是什么样子,也许您创建了一个新变量,然后进行了转换

temp.variable=temp.variable-1

然后调用该变量来执行您的url操作?

[环顾四周,我怀疑正确的做法是采取新的行动https://botpress.io/docs/10.0/getting_started/trivia_actions/,但我对这一切还是陌生的]