Facebook Messenger bot使用Spring Boot?(Facebook Messenger bot using Spring Boot?)
如今,正在创建越来越多的聊天机器人,因为如果您激活Facebook开发者帐户,并且为此目的创建Facebook页面,则该过程相对容易。
可能最流行的方法是使用NodeJS - Heroku ,如下文所述:
https://chatbotslife.com/how-to-make-a-facebook-messenger-chat-bot-in-1hr-af6bec5e7aec#.xqgu2lb46
经过研究后,我发现通过Spring启动可以与facebook建立连接(如下所述: https : //spring.io/guides/gs/accessing-facebook/ )但我没有找到任何信息或 - 甚至类似于NodeJS - 使用Spring Boot服务器处理信使对话的方法。
可以从Spring Boot请求并发送facebook messenger消息吗? 我更喜欢NodeJS,因为我已经在Spring Boot中构建了一个系统,并且在那里集成这个功能比创建一个新服务要容易得多,然后将新服务连接到现有服务。 (即使在某些情况下我肯定会坚持'微服务'结构。)
Nowadays more and more chat bots are being created, as the process is relatively easy if you activate a facebook developer account, and create a facebook page for this purpose.
Probably the most popular method is to using NodeJS - Heroku, as it is explained in the following article:
https://chatbotslife.com/how-to-make-a-facebook-messenger-chat-bot-in-1hr-af6bec5e7aec#.xqgu2lb46
After a research I found that making connection with facebook IS possible via Spring boot (as explained here: https://spring.io/guides/gs/accessing-facebook/ ) but I have not found any information or - even similar to the NodeJS - method to handle a messenger conversation using a Spring Boot server.
Is it possible to request and send facebook messenger messages from Spring Boot? I would prefer that over NodeJS, as I have a system already built in Spring Boot, and it would be much easier to integrate this feature there, than creating a new service, which would be then connected to the existing one. (even if in some cases I definitely would stuck with the 'microservice' structure.)
原文:https://stackoverflow.com/questions/41960379
最满意答案
你可以使用subplot2grid :
import numpy as np import matplotlib.pyplot as plt box = dict(facecolor='yellow', pad=5, alpha=0.2) fig = plt.figure() fig.subplots_adjust(left=0.2, wspace=0.6) # ax1 = fig.add_subplot(221) ax1 = plt.subplot2grid((3,2), (0,0)) ax1.plot(2000*np.random.rand(10)) ax1.set_title('ylabels not aligned') ax1.set_ylabel('misaligned 1', bbox=box) ax1.set_ylim(0, 2000) # ax3 = fig.add_subplot(223) ax3 = plt.subplot2grid((3,2), (1,0)) ax3.set_ylabel('misaligned 2',bbox=box) ax3.plot(np.random.rand(10)) labelx = -0.3 # axes coords # ax2 = fig.add_subplot(222) ax2 = plt.subplot2grid((3,2), (0,1)) ax2.set_title('ylabels aligned') ax2.plot(2000*np.random.rand(10)) ax2.set_ylabel('aligned 1', bbox=box) ax2.yaxis.set_label_coords(labelx, 0.5) ax2.set_ylim(0, 2000) # ax4 = fig.add_subplot(224) ax4 = plt.subplot2grid((3,2), (1,1)) ax4.plot(np.random.rand(10)) ax4.set_ylabel('aligned 2', bbox=box) ax4.yaxis.set_label_coords(labelx, 0.5) ax5 = plt.subplot2grid((3,2), (2,0), colspan=2) ax5.plot(np.random.rand(10)) ax5.set_ylabel('misaligned 3', bbox=box) plt.show()
You could use subplot2grid:
import numpy as np import matplotlib.pyplot as plt box = dict(facecolor='yellow', pad=5, alpha=0.2) fig = plt.figure() fig.subplots_adjust(left=0.2, wspace=0.6) # ax1 = fig.add_subplot(221) ax1 = plt.subplot2grid((3,2), (0,0)) ax1.plot(2000*np.random.rand(10)) ax1.set_title('ylabels not aligned') ax1.set_ylabel('misaligned 1', bbox=box) ax1.set_ylim(0, 2000) # ax3 = fig.add_subplot(223) ax3 = plt.subplot2grid((3,2), (1,0)) ax3.set_ylabel('misaligned 2',bbox=box) ax3.plot(np.random.rand(10)) labelx = -0.3 # axes coords # ax2 = fig.add_subplot(222) ax2 = plt.subplot2grid((3,2), (0,1)) ax2.set_title('ylabels aligned') ax2.plot(2000*np.random.rand(10)) ax2.set_ylabel('aligned 1', bbox=box) ax2.yaxis.set_label_coords(labelx, 0.5) ax2.set_ylim(0, 2000) # ax4 = fig.add_subplot(224) ax4 = plt.subplot2grid((3,2), (1,1)) ax4.plot(np.random.rand(10)) ax4.set_ylabel('aligned 2', bbox=box) ax4.yaxis.set_label_coords(labelx, 0.5) ax5 = plt.subplot2grid((3,2), (2,0), colspan=2) ax5.plot(np.random.rand(10)) ax5.set_ylabel('misaligned 3', bbox=box) plt.show()
相关问答
更多-
您可以随时隐藏不需要的轴。 例如,以下代码完全绕第六轴转动: import matplotlib.pyplot as plt hf, ha = plt.subplots(3,2) ha[-1, -1].axis('off') plt.show() 并得出如下图: 或者,请参阅问题的接受答案在matplotlib图中隐藏轴文本,以保持轴,但隐藏所有轴的装饰(例如刻度线和标签)。 You could always hide the axes which you do not need. For examp ...
-
首先,当您将Axes对象作为您的处置时,您正在使用调用plt 。 那条路会导致疼痛。 其次, imshow将轴刻度的纵横比设置为1.这就是为什么轴很窄的原因。 知道这一切,你的榜样变成: import numpy as np import matplotlib.pyplot as plt data = np.random.rand(10,4) #creating a wide figure with 2 subplots in 1 row fig, axes = plt.subplots(1, 2, f ...
-
我认为这里的嵌套gridspec示例是您正在寻找的。 我已经将他们的例子改编为你所描述的网格模式的模型,它使用gridspec创建一个轴列表,然后迭代它们的索引来填充它们。 这种方法应该符合您对“3x3子图布局的需求,每个子图本身被划分为3x1子图布局”。 import matplotlib as mpl from matplotlib import gridspec from matplotlib import pyplot as plt f= plt.figure(figsize=(5, 5)) gs ...
-
图是一个数字。 你不能在图中有一个数字。 通常的方法是创建一个图形,创建一个或多个子图,在子图中绘制一些东西。 如果你想要在不同的轴或图中绘制某些东西,可能有必要将绘图包装在一个以轴为参数的函数中。 然后,您可以使用此函数绘制新图形的轴,或绘制到具有许多子图的图形轴。 import numpy as np import matplotlib.pyplot as plt def myplot(ax, data_x, data_y, color="C0"): ax.plot(data_x, data_ ...
-
"equal" for the 5 imshow() calls (check by calling ,纵横比设置为"equal" for the 5 calls (check by calling ax1.get_aspect()进行calls (check by calling ) while for ax5, it is set to auto which gives you the non-square shape you observe. I'm guessing which gives you ...
-
当然,还有非常复杂的解决方案,例如gridspec模块,这在很多情况下都是非常整洁的工具。 然而,当像这样有一个相当简单的需求时,你仍然可以照常使用add_subplot() 。 import matplotlib.pyplot as plt fig = plt.figure() ax1 = fig.add_subplot(321) ax2 = fig.add_subplot(323) ax3 = fig.add_subplot(325) ax4 = fig.add_subplot(222) ax5 = ...
-
你可以使用subplot2grid : import numpy as np import matplotlib.pyplot as plt box = dict(facecolor='yellow', pad=5, alpha=0.2) fig = plt.figure() fig.subplots_adjust(left=0.2, wspace=0.6) # ax1 = fig.add_subplot(221) ax1 = plt.subplot2grid((3,2), (0,0)) ax1.p ...
-
不同之处在于plt.subplot和fig.add_subplot之间。 更确切地说,在第一种情况下,您使用pyplot的散点函数plt.scatter ,在第二种情况下,您使用轴的scatter , ax.scatter 。 plt.scatter是一个2D函数。 它将第三个参数解释为散点的大小,并在二维中绘制一个散点图。 (您会看到z轴根本没有缩放。) 当使用ax.scatter , ax是3D轴( matplotlib.axes._subplots.Axes3DSubplot )。 它的scatter ...
-
如何将matplotlib图对象包含为子图?(How do I include a matplotlib Figure object as subplot? [duplicate])[2022-09-29]
你不能把figure放在一个figure 。 您应该修改绘图函数以将axes对象作为参数。 我也不清楚为什么那里有kwarg figure ,我认为它是继承工作方式的工件,文档自动生成的方式,以及一些getter / setter工作的自动化方式。 如果你注意到,它说figure在Figure文档中没有记载,所以它可能不会做你想要的;)。 如果你向下挖掘一下,那个kwarg真正控制的是创建的轴也附着的图形,这不是你想要的。 通常,在图形之间移动现有的轴/艺术家并不容易,需要重新连接太多的内部管道。 我认为它 ... -
Python&Matplotlib:创建两个不同大小的子图(Python & Matplotlib: creating two subplots with different sizes)[2022-08-29]
此解决方案是否满足? import matplotlib.pyplot as plt list1 = [1,2,3,4] list2 = [4,3,2,1] somecondition = True plt.figure(1) #create one of the figures that must appear with the chart if not somecondition: ax = plt.subplot(111) #create the first subplot that wi ...