打破次元壁球体相互碰撞_打破软件的第四壁

打破次元壁球体相互碰撞

by Alex Bunardzic

由Alex Bunardzic

打破软件的第四壁 (Breaking The Fourth Wall In Software)

或者,旧事物又是新事物 (Or, Everything Old Is New Again)

The phenomenon of breaking the fourth wall is well known in the world of theater and cinematography. The breaking of the so-called ‘fourth wall’ is typically brought about by one of the protagonists in the movie suddenly turning toward the camera and addressing the viewing audience, thus breaking the illusion that we’re witnessing a real-life event.

打破第四壁的现象在剧院和电影摄影界众所周知。 电影中的一位主角突然转向摄像机并向观看的观众讲话,通常是造成所谓“第四墙”的破裂,从而打破了我们目睹现实生活中的幻想。

But how does breaking the fourth wall work in software?

但是,打破第四道壁垒如何在软件中起作用?

早期的人机界面 (Early Human-Computer Interfaces)

The first computers were big and expensive and finicky. The way humans interacted with computers at that time was typically by feeding it a stack of punched cards.

第一台计算机又大又昂贵又挑剔。 当时人们与计算机进行交互的方式通常是向计算机喂入一叠打Kong卡

早期的界面令人生畏 (Early Interfaces Were Intimidating)

You obviously needed a university degree in order to operate computers.

您显然需要大学文凭才能操作计算机。

早期界面笨拙 (Early Interfaces Were Clunky)

A lot of buttons and switches and dials and levers. Intimidating and clunky.

很多按钮和开关以及转盘和操纵杆。 令人生畏和笨拙。

突破-文字! (Breakthrough — Text!)

Late 1960s — early 1970s witnessed the introduction of the so-called computer terminal. Emulating a typewriter for entering commands, and then displaying the results of the evaluated text on the monitor that looked like a TV screen.

1960年代末-1970年代初见证了所谓计算机终端的问世。 模拟用于输入命令的打字机,然后在看起来像电视屏幕的监视器上显示评估文本的结果。

文字很直观 (Text Is Intuitive)

Pretty much all people find text to be very intuitive — close to the way we think and speak. It feels much more natural to speak to the machine than it is to twoddle the knobs, flip the switches, and pull the levers (not to mention punch the cards or rewire the circuits).

几乎所有人都认为文本非常直观-接近我们的思维和说话方式。 与机器说话比从动旋钮,翻转开关和拉动操纵杆(更不用说打卡或给电路重新布线)感觉自然得多。

但是计算机笨拙 (But Computers Are Clunky)

In the early days of computers, if you type a wrong command or use wrong syntax, the computer used to throw a tantrum. Temperamental beasts!

在计算机的早期,如果键入错误的命令或使用错误的语法,则计算机会发脾气。 气质的野兽!

只有这些人知道如何与计算机对话 (Only These People Knew How To Talk To Computers)

You may recognize some faces on the group photo below.

您可能会在下面的集体照中认出一些面Kong。

用图形界面替换文本—桌面隐喻 (Replace Text With Graphical Interface — The Desktop Metaphor)

Use pictorial representation to shield people from having to memorize awkward commands and syntax when operating computers. The idea was to present users with some familiar scenery — for example, their desktop. Everyone is familiar with the idea of having a desktop with file folders containing files and also a trash can at the side of the desk etc.

使用图形表示法可以避免人们在操作计算机时不得不记住笨拙的命令和语法。 想法是向用户展示一些熟悉的风景-例如他们的桌面。 每个人都熟悉使桌面带有文件夹的想法,该文件夹包含文件,并且在办公桌侧面还有一个垃圾桶等。

This Graphical User Interface (GUI) was deemed as being even more intuitive than text.

这种图形用户界面(GUI)被认为比文本更直观。

图形用户界面Swift陷入可怕和不直观的状态 (GUIs Quickly Mushroomed Into Something Scary and Non-Intuitive)

How is the interface below intuitive? It is as frustrating as the arcane and awkward syntax that the early computers insisted on when processing text.

下面的界面如何直观? 就像早期计算机在处理文本时所坚持的神秘而笨拙的语法一样令人沮丧。

一张图片胜过千言万语 (A Picture Is Worth A Thousand Words)

True. But what if most of those thousand words are gibberish? What’s the worth of that?

真正。 但是,如果这千个单词中的大多数都是乱码怎么办? 那有什么价值?

底线:人们发现GUI令人沮丧 (Bottom Line: People Find GUIs Frustrating)

GUIs typically present us with too much information at once. Then the onus is on us to digest all that and try to make sense out of it.

GUI通常一次向我们提供太多信息。 然后,我们有责任消化所有这些东西,并设法从中弄清楚。

GUIs also tend to enforce ‘one size fits all’ approach, which is not very user-centric.

GUI也倾向于实施“一刀切”的方法,这种方法不是非常以用户为中心的。

那么那是什么解决方案? (So What’s The Solution Then?)

What if, instead of this poorly thought out buffer that consists of intermediary graphical representation, we were to revert to plain text again? It is, after all, much easier to focus and follow simple discussion threads than it is trying to navigate hairy, convoluted GUIs.

如果不是我们重新考虑了纯文本格式 ,而不是由中间图形表示形式组成的缓冲区,那该怎么办? 毕竟,与试图浏览冗长而复杂的GUI相比,集中精力和遵循简单的讨论线程要容易得多。

但是计算机很脆弱,不会像GUI那样宽容 (But Computers Are Brittle And Will Not Be As Forgiving As GUIs)

We have grown to depend on GUIs as we would depend on training wheels. Installing training wheels gives us a sense of safety — we cannot fall, and yet we can somehow move forward and get to our destination.

我们已经越来越依赖GUI,就像我们依赖训练轮一样。 安装辅助轮可以给我们带来安全感-我们不能跌倒,但是我们可以以某种方式前进并到达目的地。

使用训练轮无法走得很远 (Can’t Get Very Far Using Training Wheels)

Training wheels are okay for peddling around our back yard, but we can’t use them effectivelly in real life situations.

训练轮可以在我们的后院兜售,但是在现实生活中我们无法有效地使用它们。

如何卸下训练轮并学会正确骑行? (How To Remove Training Wheels And Learn To Ride Properly?)

Break the fourth wall!

打破第四壁!

How do we break the fourth wall? Stop pushing pixels!

我们如何打破第四堵墙? 停止推像素!

How can we stop pushing pixels?

我们如何停止推像素?

令人沮丧的例子 (Frustrating Example)

Say we order something online. The next week we may be wondering about the status of our order (hasn’t, for some reason, arrived yet). Frustrated, we open the browser, go to the online store, log in, and then try to navigate to the order status page.

假设我们在线订购商品。 下周,我们可能想知道订单的状态(由于某种原因尚未到达)。 沮丧的是,我们打开浏览器,进入在线商店,登录,然后尝试导航到订单状态页面。

To reach the order status page, we have to navigate through the veritable jungle of confusing menus, shifting layouts, poorly styled links (often barely visible on the page), and so on. To add insult to an injury, these elements keep constantly changing, so we cannot rely on our muscle memory from previous navigation sessions.

要进入“ 订单状态”页面,我们必须浏览真实的丛林,其中包括令人迷惑的菜单,切换布局,样式不良的链接(通常在页面上几乎看不到)等等。 更糟的是,这些元素不断变化,因此我们不能依靠以前的导航会话中的肌肉记忆。

少令人沮丧的例子 (Less Frustrating Example)

What if, instead of doing all of the above gymnastics and acrobatics, we just do the following:

如果我们只是做以下事情,而不是做以上所有的体操和杂技活动,该怎么办:

Go to the command line (say in Messenger or Slack etc.) and type ‘@merchant_name what’s the status of my order?

转到命令行(例如MessengerSlack等),然后输入' @merchant_name我的订单状态如何? '

That way, we let the merchant service (i.e. Amazon or Etsy or Ebay etc.) do the legwork on our behalf.

这样,我们让商家服务(即Amazon或Etsy或Ebay等)代表我们完成工作。

Which of the two ‘check order status’ experiences is more intuitive?

两种“检查订单状态”体验中哪一种更直观?

猜猜是什么-我们刚刚打破了软件的第四壁! (Guess What — We Just Broke The Fourth Wall In Software!)

By foregoing the GUI, we have switched to interacting with some online service using plain text. And it felt quite natural. Notice how, by doing that, we were not expected to undergo any training.

通过使用GUI,我们已切换为使用纯文本与某些在线服务进行交互。 而且感觉很自然。 请注意,这样做不会导致我们没有接受任何培训。

How’s that possible? Simple — instead of interacting with the bare metal computing machinery, we got in touch with a sophisticated chatbot whose role is to know how to parse and interpret colloquial English text.

那怎么可能 简单-我们没有与裸机计算机交互,而是与一个复杂的聊天机器人联系,该聊天机器人的作用是知道如何解析和解释口语英语文本。

我们如何参与聊天机器人? (How Do We Get Involved With A Chatbot?)

We /invite it to our channel. For example, say we find out there is a chatbot that specializes in restaurant recommendations. We wish to get in touch with that bot, and after finding out the name of the bot (say, restobot), we ‘hire’ that bot to work for us by typing:

我们/邀请它到我们的频道。 例如,假设我们发现有一个专门从事餐厅推荐的聊天机器人。 我们希望与该机器人保持联系,并在找到该机器人的名称(例如restobot )之后,通过键入以下内容来“租用”该机器人以为我们工作:

/invite @restobot

/邀请@restobot

Once invited to your channel, this bot will remain always online, listening attentively for its name to get mentioned.

受邀加入您的频道后,该漫游器将始终保持在线状态,专心聆听其名字而被提及。

机器人是缓冲 (The Bot Is The Buffer)

Similar to how a GUI was the buffer between us, human users, and the cold, bare computing machinery, bots are now replacing GUIs as that warm and fuzzy buffer. Bots are shielding us from having to deal with the temperamental machinery by translating our plain English commands into something that the underlying computing services can understand and work with.

与GUI成为我们,人类用户和寒冷的裸机之间的缓冲区类似,机器人现在正在将GUI替换为温暖而模糊的缓冲区。 僵尸程序将普通的英语命令翻译成基础计算服务可以理解和使用的东西,从而使我们不必处理气质机器。

机器人的价值主张是什么? (What’s The Value Proposition Of Bots?)

Bots are attentive to human needs and sensitive to human frailty.

机器人对人类的需求关注, 对人类的脆弱也很敏感

那么这是革命性的改变吗? (So Is This A Revolutionary Change?)

Not really. It’s the natural outcome of the advancements we’ve made in the field of human-computer interaction. So it’s more of an evolutionary change.

并不是的。 这是我们在人机交互领域取得的进步的自然结果。 因此,这更多是进化的变化。

In actuality, this conversation-based interface is not all that different from operating computers via GUIs. Because, if we examine a bit closer what’s going on behind the surface of a typical GUI processing, we’ll find the following scenario:

实际上,这个基于对话的界面与通过GUI操作计算机并没有什么不同。 因为,如果我们仔细研究一下典型的GUI处理表面背后发生的情况,则会发现以下情况:

  • A user wants to ask the computer to do something

    用户想让计算机做某事
  • User goes to the screen/page where they get presented with one or more input fields

    用户转到显示一个或多个输入字段的屏幕/页面

  • These input fields, sometime referred to as text boxes, accept text from the user

    这些输入字段(有时称为文本框 )接受用户的文本

  • The GUI then listens to the user’s gestures, such as ‘send’ or ‘submit’ gesture

    然后,GUI会监听用户的手势,例如“发送”或“提交”手势
  • Once the event signalling the expected gesture occurs, the GUI turns around and sends text to the underlying servers

    一旦发生表示预期手势的事件,GUI就会转过身并将文本发送到底层服务器

GUI也是文本驱动的 (GUIs Are Also Text-Driven)

Similar to how bots operate, GUIs also posses the knowledge of how to collect text from users and then formulate the collected values using the strict syntax that the back-end computers can understand.

与bot的操作方式类似,GUI也具有以下知识:如何从用户那里收集文本,然后使用后端计算机可以理解的严格语法来制定所收集的值。

So if that’s the case, where do pixels come into play?

因此,如果是这样,像素在哪里起作用?

Most of the time, pixels are being used as decoration. They typically sugarcoat the screen, or a web page, and dress it up in a robe that looks more familiar to the users. Such as, for example, dressing up a web form to look similar to the paper form.

大多数时候,像素被用作装饰 。 他们通常在屏幕或网页上涂上糖衣,然后将其打扮成对用户来说更熟悉的长袍。 例如,装饰Web表单以使其看起来类似于纸质表单。

Doing that decompresses the tension users may feel when attempting to work with computers. The intent is to demystify the interaction, and make it feel similar to everyday interactions one may encounter when dealing with various non-virtual services.

这样做可以减轻用户在尝试使用计算机时可能会感到的紧张感。 目的是使交互变得神秘,并使其感觉类似于在处理各种非虚拟服务时可能遇到的日常交互。

删除像素化的装饰品,剩下的是什么? (Remove Pixelated Decorations, And What Are We Left With?)

One word — microcopy.

一个字- 显微镜

What is microcopy?

什么是显微镜

In the above example, microcopy is any text placed next to the GUI control. In a GUI form, we may ask users to enter their phone number. Often times, people are not sure if they want to do that, and also why would we need their personal information? So we place a simple, direct sentence in the brackets, right next to the caption asking for the phone number, explaining the purpose of that request. For example, “we need your phone number for shipping-related questions”.

在上面的示例中, 显微镜复制是放置在GUI控件旁边的任何文本。 在GUI表单中,我们可能会要求用户输入他们的电话号码。 通常,人们不确定他们是否愿意这样做,为什么我们需要他们的个人信息? 因此,我们在标题旁边的括号中输入一个简单直接的句子,询问电话号码,以说明该请求的目的。 例如,“我们需要您的电话号码来解决运输方面的问题”。

Or, we may offer a microcopy that is a bit more verbose, such as in the example below:

或者,我们可能会提供更为详细的显微镜 ,例如以下示例:

对话话题 (Conversational Thread)

If we imagine removing all pixels and with it the graphical user interface, what we’re left with is a simple conversational thread that gets recorded between the user and the computer.

如果我们想象删除所有像素并使用图形用户界面,那么剩下的就是一个简单的对话线程 ,该线程在用户和计算机之间记录。

对话界面的优势是什么? (What Are The Advanatages Of Conversational Interfaces?)
  • Intuitive

    直觉的
  • Sensitive to human frailty (the bot will try to clarify human request if initially not clearly understood)

    敏感于人类的脆弱性(如果最初没有清楚地理解,机器人将尝试澄清人类的要求)
  • Familiar (everyone is already fully accustomed to chatting with family/friends/coworkers)

    熟悉(每个人已经完全习惯了与家人/朋友/同事聊天)
  • Consistent experience across all devices (immune to any concerns/issues related to layouts, fonts, colors, etc.)

    跨所有设备的一致体验(不受与布局,字体,颜色等有关的任何关注/问题)
  • Guarantees full user ownership of the conversation — fully personalized discussion thread is forever recorded and owned by the human user (full transparency, complete audit)

    确保对话的完全用户所有权-完全个性化的讨论线程由人类用户永久记录和拥有(完全透明,完全审核)
对话商务 (Conversational Commerce)

As we’re moving into the post-web 2.0 world, the universal slogan ‘content is king’ now becomes ‘commerce is king’. In the web 2.0 world, when a user completes a transaction via GUI, all the steps that transpired between the user and the online service may have been recorded by the back-end service, but are opaque to the user. In the world of conversational commerce, every step that transpired between the user and the online service is recorded in the conversational thread and is fully owned by the user.

随着我们进入后Web 2.0世界,通用口号“内容为王”现在变成“商业为王”。 在Web 2.0世界中,当用户通过GUI完成交易时,用户和在线服务之间发生的所有步骤可能已被后端服务记录下来,但对用户而言是不透明的。 在对话商务的世界中,用户和在线服务之间发生的每个步骤都记录在对话线程中,并由用户完全拥有。

对话界面体验类似于常规的客户支持体验 (Conversational Interface Experience Is Similar To Regular Customer Support Experience)

Similar to how calling a 1–800 number was a mainstream customer support channel before the emergence of web 2.0 and the mobile apps, we’re moving back into conversing directly with the customer suport. Only this time, instead of being put on an indefinite hold and forced to listen to horrible muzak, we’re conversing with bots which are always on and are much faster and more accurate, more detialed than human workforce.

与在Web 2.0和移动应用程序出现之前,拨打1–800号码成为主流客户支持渠道的方式类似,我们正回到直接与客户支持进行对话的方式。 仅这次,我们没有被无限期搁置并被迫听可怕的muzak,而是与一直在使用的机器人进行对话,这些机器人比人类劳动力更快速,更准确,更灵活。

And same as with the 1–800 scenarios, if our call for some reason cannot get resolved in satisfactory manner, we can easily escalate. In the old regime we would ask the customer service representative to talk with their supervisor, and in the new regime we would ask the bot-agent to put us in touch with the human operator.

与1–800情形一样,如果由于某种原因我们的通话无法以令人满意的方式解决,我们可以轻松升级 。 在旧的体制下,我们将要求客户服务代表与他们的主管对话,而在新的体制下,我们将要求漫游器代理使我们与人工操作员保持联系。

让我们现在创建自己的机器人! (Let’s Create Our Own Bot Now!)

Perhaps the best way to grasp this transition from graphical to text-based user interface is to roll up our sleeves and create a bot from ground up. Creating a bot is quite easy, because the tools necessary for building bots have been largely commoditized. Still, I feel that merely creating a bot would not be an efficient nor convincing demonstration of the importance of conversational commerce. That’s why I’m proposing that we here learn not only how to create a bot, but also how to create a bot that is capable of doing something useful for us.

掌握从图形用户界面到基于文本的用户界面的这种过渡的最好方法也许就是卷起袖子,从头开始创建一个机器人。 创建机器人很容易,因为构建机器人所需的工具已在很大程度上商品化了。 尽管如此,我仍然认为仅仅创建一个机器人并不能有效地证明会话商务的重要性。 这就是为什么我建议我们在这里不仅学习如何创建机器人,而且还要学习如何创建能够为我们做一些有用的事情的机器人。

For example, let’s create a bot that will help us get in touch with some e-commerce service by using plain text as the user interface.

例如,让我们创建一个机器人,通过使用纯文本作为用户界面来帮助我们与某些电子商务服务取得联系。

首先创建在线商务服务 (Create Online Commerce Service First)

For the sake of brevity, let’s create a simple e-commerce site that will host an inventory of products. Those products will be offered for sale, and some of the products on sale will also be offered at a discount price.

为了简洁起见,让我们创建一个简单的电子商务站点来托管产品清单。 这些产品将被出售,某些产品也将以折扣价出售。

We will use state-of-the-art web development framework (Ruby on Rails) for building this service. If you don’t have the Rails framework installed, please refer to the Rails site for instructions on how to get it installed on your computer.

我们将使用最新的Web开发框架( Ruby on Rails )来构建此服务。 如果您尚未安装Rails框架,请访问Rails站点以获取有关如何在计算机上安装它的说明。

Once installed, we use Rails to create a new site. Open the terminal and type:

安装完成后,我们将使用Rails创建一个新站点。 打开终端并输入:

rails new your_site_name
新的your_site_name

Rails will then create the new project for you, and once you navigate to your new project (by typing cd your_site_name), you are ready to create the inventory of products to be hosted on the new site. We will create a resource called Product, and will then assign several attributes to it:

然后,Rails将为您创建一个新项目,并且一旦导航到新项目(通过输入cd your_site_name ),就可以创建要在新站点上托管的产品清单了。 我们将创建一个名为Product的资源,然后为其分配几个属性:

rails generate scaffold Product name:string price:decimal on_special:boolean discount_percentage:integer description:text
rails generate scaffold产品名称:字符串价格:十进制on_special:布尔型Discount_percentage:整数说明:文本

The above command will create the resource called Product and will implement product attributes, such as product name, its price, whether or not it’s on special, and the discount percentage.

上面的命令将创建一个名为Product的资源,并将实现产品属性,例如产品名称,价格,是否特价以及折扣率。

Now is the time to create a database where the inventory of products will get stored. We do that by using the specifications that got created with the previous command. The command to create and install the products database is as follows:

现在是时候创建一个用于存储产品库存的数据库。 我们通过使用上一条命令创建的规范来做到这一点。 创建和安装产品数据库的命令如下:

rake db:migrate
耙db:migrate

The only thing left to do is to start the server and verify that the web site we’ve just created is working as expected:

剩下要做的唯一一件事就是启动服务器并验证我们刚刚创建的网站是否按预期工作:

rails s
滑轨
维护产品库存 (Maintain Inventory Of Products)

Now that we’ve created our products database and our web site, we should navigate to it and add some products. Open up the web browser and navigate to the http://localhost:3000/products URL.

现在,我们已经创建了产品数据库和网站,我们应该导航到该数据库并添加一些产品。 打开Web浏览器并导航到http:// localhost:3000 / products URL。

Of course, the product inventory page will be empty, because we haven’t added any products yet. Let’s do that by clicking on the ‘New Product’ link.

当然,产品清单页面将为空,因为我们尚未添加任何产品。 让我们通过单击“新产品”链接来做到这一点。

After entering some values, we click on the “Create Product” button and the product is now added to the inventory. Let’s enter a few more products (remembering to click on the “On special” checkbox for some of them).

输入一些值后,我们单击“创建产品”按钮,现在该产品已添加到库存中。 让我们输入更多产品(记住要单击其中一些的“ On special”复选框)。

Now that we have several products in our inventory, time to build a conversational commerce bot. What will be the usefulness of that bot? In order to keep things simple, we will endow this bot with the ability to answer text commands enquiring about the products that are on special.

现在我们的库存中有几种产品,该建立一个对话式商务机器人。 该机器人的作用是什么? 为了使事情简单,我们将使该机器人能够回答查询特殊产品的文本命令。

我们的机器人将住在哪里? (Where Will Our Bot Live?)

A bot must be able to listen to text messages arriving from users, and the best way to make that happen is to add the bot to some messaging platform. Currently, the most attractive messaging platform for adding bots is Slack, so we’re going to use it to demonstrate how to build conversational commerce.

机器人必须能够侦听来自用户的短信,而实现这一目标的最佳方法是将机器人添加到某些消息传递平台。 当前,用于添加机器人的最有吸引力的消息传递平台是Slack ,因此我们将使用它来演示如何建立对话式商务。

Signup with Slack (if you’re not a member already), and then go to:

使用Slack进行注册(如果您还不是会员),然后转到:

https://yourteam.slack.com/services/new/bot

https://yourteam.slack.com/services/new/bot

You will be asked to specify the name of your bot. Let’s call our bot ‘gofer’.

系统将要求您指定机器人的名称。 让我们将机器人称为“ gofer”。

After clicking the “Add bot integration” button, we will be able to set our gofer up on Slack. First thing first, let’s choose the icon that will represent our bot. I choose my favourite robot, Bender.

单击“添加机器人集成”按钮后,我们将能够在Slack上设置gofer。 首先,让我们选择代表我们的机器人的图标。 我选择了我最喜欢的机器人本德尔。

We can also add bot’s first and last name and a description outlining bot’s capabilities.

我们还可以添加bot的名字和姓氏以及描述bot功能的描述。

After saving the integration, we notice the API Token; this token is extremely important, as it allows the integration between our hand crafted bot and the Slack platform. Let’s copy the value of that API Token for future reference.

保存集成后,我们会注意到API令牌; 这个令牌非常重要,因为它允许我们的手工机器人与Slack平台集成。 让我们复制该API令牌的值以供将来参考。

最后一步-打造机器人 (Final Step — Crafting Our Bot)

Now’s the time to open the source code of our e-commerce product inventory site. We must add bot to this site, because the bot will be able to utilize the services built into our inventory site and aswer the questions coming from the Slack users.

现在是时候打开我们的电子商务产品清单网站的源代码了。 我们必须将漫游器添加到此站点,因为该漫游器将能够利用内置到我们的库存站点中的服务,并避免来自Slack用户的问题。

First thing we need to do is navigate to the config folder in our product inventory site and create a new file. That file will contain the Slack API Token. We can name this file anything we want; I prefer to keep its name simple, so I call it api.rb. This file will consist of only one line of code:

我们需要做的第一件事是导航到我们产品清单站点中的config文件夹并创建一个新文件。 该文件将包含Slack API令牌。 我们可以根据需要命名该文件。 我更喜欢保持其名称简单,因此将其命名为api.rb。 该文件仅包含一行代码:

ENV[‘SLACK_API_TOKEN’]=’xoxb-23830295172-r5CzhzDnUSZQfUfXWmR’
ENV ['SLACK_API_TOKEN'] ='xoxb-23830295172-r5CzhzDnUSZQfUfXWmR'

Next we need to tell Rails framework to load that API Token during the intialization phase. We open the config/environment.rb file, and add the following two lines of code:

接下来,我们需要告诉Rails框架在初始化阶段加载该API令牌。 我们打开config / environment.rb文件,并添加以下两行代码:

api = File.join(Rails.root, ‘api.rb’)

api = File.join(Rails.root,'api.rb')

Now that we have declared Slack API Token and instructed Rails to load it, we need to add our bot to the project. The best way to do that is to navigate to the app folder, and create a new folder simply named bots.

现在,我们已经声明了Slack API令牌并指示Rails加载它,我们需要将bot添加到项目中。 最好的方法是导航到app文件夹,并创建一个名为bots的新文件夹。

Create a new file in the app/bots folder, and name it real_time_messaging.rb. This file will deal with the thread used for our bot to listen for the incoming messages. Add these lines to the file, and save it:

app / bots文件夹中创建一个新文件,并将其命名为real_time_messaging.rb。 该文件将处理我们的机器人用来侦听传入消息的线程。 将这些行添加到文件,并保存:

$:.unshift File.dirname(__FILE__)
$ :. unshift File.dirname(__ FILE__)
Thread.abort_on_exception = true
Thread.abort_on_exception = true

Thread.new do

Thread.new做

Gofer.run

Gofer.run

You have probably noticed that in the file above we have mentioned Gofer; we managed to get ahead of ourselves by mentioning the bot we havent created yet. But that’s okay, because we’re not ready yet to kick start the bot service listening on the channel.

您可能已经注意到,在上面的文件中,我们提到了Gofer ; 通过提及我们尚未创建的机器人,我们设法取得了领先。 但这没关系,因为我们还没有准备好启动在频道上监听的bot服务。

So the real challenge now is to figure out how to craft our bot named Gofer. For the sake of brevity, we will cheat here by leveraging the commodity service known as Slack Ruby Bot. Leveraging this commodity allows us to save time that would’ve otherwise be spent on coding the low level web sockets processing, which is a fairly involved exercise.

因此,现在真正的挑战是弄清楚如何制作名为Gofer的机器人。 为了简洁起见,我们将在此处利用称为Slack Ruby Bot的商品服务来作弊。 利用这种商品可以节省我们原本会花在编写底层Web套接字处理上的时间,这是一项相当复杂的工作。

The quickest way to leverage this commodity is to open the Gemfile found in the root of the project, and add the following line to it:

利用这种商品的最快方法是打开在项目根目录中找到的Gemfile ,并在其中添加以下行:

gem ‘slack-ruby-bot’
宝石'slack-ruby-bot'

Save the file and then go to the command line to the root of the project and run:

保存文件,然后转到项目根目录的命令行并运行:

bundle install
捆绑安装

When the installation completes, will will have baked in our Slack Ruby Bot commodity service, which we will leverage when creating our Gofer bot.

安装完成后,将在我们的Slack Ruby Bot商品服务中进行烘烤,我们将在创建Gofer机器人时加以利用。

But before we jump into crafting the bot logic, we need to complete one more step related to the underlying plumbing needed for the Slack bot to work properly. Navigate to the config/initializers folder, and create a new file simply called bot.rb. This is a simple file consisting of only one line of code:

但是,在开始制作机器人逻辑之前,我们需要完成与Slack机器人正常工作所需的基础管线相关的另一步骤。 导航到config / initializers文件夹,并创建一个名为bot.rb的新文件。 这是一个仅包含一行代码的简单文件:

require File.join(Rails.root, ‘app/bots/real_time_messaging’)
需要File.join(Rails.root,'app / bots / real_time_messaging')

It is simply instructing Rails to load the real_time_messaging.rb file on initialization. And if we look back into the contents of the real_time_messaging.rb file, we will see that, once the web site boots, it will also run a thread that is responsible for running the Gofer bot.

它只是指示Rails在初始化时加载real_time_messaging.rb文件。 并且,如果我们回顾real_time_messaging.rb文件的内容,我们将看到,一旦网站启动,它还将运行负责运行Gofer机器人的线程。

And finally, on to creating the bot logic! Create a new file in the app/bots folder, and name it gofer.rb. This file will declare Gofer bot as inheriting its capabilities from the commodity we’ve just installed — SlackRubyBot::Bot.

最后,继续创建机器人逻辑! 在app / bots文件夹中创建一个新文件,并将其命名为gofer.rb 。 该文件将声明Gofer机器人从我们刚刚安装的商品SlackRubyBot :: Bot继承其功能。

class Gofer< SlackRubyBot::Bot
类Gofer <SlackRubyBot :: Bot

This bot inherits some rudimentary capabilities from SlackRubyBot, such as the ability to respond to commands. And these commands is what we’ll be teaching this bot, telling it how to respond to each command it receives.

该机器人从SlackRubyBot继承了一些基本功能例如响应命令的功能。 这些命令就是我们将要教给该机器人的东西,告诉它如何响应收到的每个命令。

Let’s start with something extremely simple — let’s teach our Gofer bot how to handle the ‘help’ command. Add the following command definition to the gofer.rb file:

让我们从一个非常简单的事情开始-让我们教我们的Gofer机器人如何处理'help'命令。 将以下命令定义添加到gofer.rb文件:

command ‘help’ do |bot, thread|

命令'help'做|机器人,线程|

bot.say(channel: thread.channel, text: “Help is on its way.”)

bot.say(渠道:thread.channel,文本:“帮助即将来临。”)

This command is going to use the bot to get it to display the text ‘Help is on its way.’ to the channel from where it was asked for help.

该命令将使用漫游器使其显示“正在帮助”文本。 到从那里寻求帮助的渠道。

Save the file, go to the command line and start the server (rails s). You will now notice additional messages on the command line when the server starts:

保存文件,转到命令行并启动服务器( rails )。 现在,当服务器启动时,您将在命令行上注意到其他消息:

Now that our bot Gofer is successfully connected to our Slack team, we can test it. Go to your Slack team, and you will see that gofer bot is online (there is a green semaphore ligh next to its name). Click on its name, and then type ‘help’. You will see that the bot immediately responds with the text we’ve given it above.

现在我们的机器人Gofer已成功连接到我们的Slack团队,我们可以对其进行测试。 转到您的Slack团队,您将看到gofer bot在线(其名称旁边有一个绿色的信号灯光 )。 单击其名称,然后键入“帮助”。 您会看到该机器人立即用我们上面给出的文本进行响应。

OK, neat, so now we see that our bot is working. But how do we get it to tell us what products are offered on special at the moment? Simple — we just add a new command (let’s call it ‘promo’ for simplicity) and instruct the bot to gather information on the products with discounted prices and send us the list back.

好的,很整洁,所以现在我们看到我们的机器人正在运行。 但是,我们如何得知当前特价商品呢? 简单-我们只需添加一个新命令(为简单起见,我们将其称为“促销”),并指示该漫游器以折扣价格收集有关产品的信息,然后将列表发送给我们。

Save the file, restart the server, and flip over to Slack to ask gofer what’s on special.

保存文件,重新启动服务器,然后转到Slack询问gofer有什么特别之处。

Just to verify that the bot is indeed working in real time, go to the product inventory and make some changes. Like, remove the discount for the Hat and maybe add discount for some other product. After you do that and ask gofer what’s on promo, it will tell you all the latest details.

只是为了验证该机器人确实是实时工作,请转到产品清单并进行一些更改。 像,删除帽子的折扣,也许增加一些其他产品的折扣。 然后,询问gofer促销内容,它将告诉您所有最新信息。

结论 (Conclusion)

Latest trends have shown that more and more people tend to spend majority of their online time chatting. As of the early 2016, almost 1 billion active users are spending time on Messenger and other chat apps. As people are getting familiar with texting with their friends, family, and coworkers, they are also slowly becoming acclimatized to chatting with bots. That experience is offering a more intuitive way to get things done, and all signs indicate that this new way of interacting with computers is what people at large seem to prefer.

最新趋势表明,越来越多的人倾向于将大部分在线时间都花在聊天上。 截至2016年初,将近10亿活跃用户将时间花在Messenger和其他聊天应用程序上。 随着人们对与朋友,家人和同事发短信的熟悉,他们也逐渐适应与机器人聊天。 这种体验提供了一种更直观的方式来完成任务,所有迹象表明,这种与计算机交互的新方式似乎是人们普遍喜欢的方式。

We have attempted to illustrate how will this transition work by walking the readers through the hands-on session on how to create their own bots. Once the first trial bot gets created, we realize that sky is the limit — there are so many useful things these bots can do, so let’s get cracking!

我们试图通过引导读者逐步介绍如何创建自己的机器人,来说明这种过渡的工作方式。 一旦创建了第一个试用版bot,我们就意识到天空是极限–这些bot可以做很多有用的事情,所以让我们开始吧!

更新资料 (Update)

I was invited by the RED Academy to deliver the talk on Conversational Commerce and the Bot ‘revolution’. The talk was recorded and can be viewed below:

我受RED学院的邀请进行了有关对话商务和Bot“革命”的演讲。 谈话已录制,可以在下面查看:

Intrigued? Want to learn more about the bot revolution? Read more detailed explanations here:

感兴趣吗? 想更多地了解机器人革命? 在此处阅读更多详细说明:

How To Build A Stateful BotThe Age of Self-Serve is Coming to an EndOnly No Ux Is Good UXStop Building Lame Bots!Four Types Of BotsIs There A Downside To Conversational Interfaces?Are Bots just a Fad? Are GUIs really Superior?How to Design a Bot ProtocolBots Are The Anti-AppsHow Much NLP Do Bots Need?Screens Are For Consumption, Not For Interaction

如何建立有状态的机器人自助服务的时代即将结束, 只有UX才是好的UX 停止建立La脚的机器人! 四种类型的Bot 对话界面有不利之处吗? 机器人只是一种时尚吗? GUI真的优越吗? 如何设计Bot协议 BotReact用程序 Bot需要多少NLP? 屏幕用于消费而非交互

翻译自: https://www.freecodecamp.org/news/breaking-the-fourth-wall-in-software-d08a25df34b7/

打破次元壁球体相互碰撞

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值