messenger

Android中Messenger的使用

浪尽此生 提交于 2019-12-07 02:49:00
我们使用Handler都是在一个进程中使用的,如何跨进程使用Handler? 其实这个问题不难解决,自己动手对binder进行一些封装就可以简单实现。但是当你看系统源码,就会发现,其实这些android都已经为我们做好了。 使用android系统的 android.os.Messenger 可以很方便的跨进程使用Handler。下面是示例程序。 首先是服务端。 public class MessengerTestService extends Service { protected static final String TAG = "MessengerTestService"; private Handler mHandler = new Handler() { @Override public void handleMessage(Message msg) { switch (msg.what) { case 1: Log.d(TAG, "收到消息"); //获取客户端message中的Messenger,用于回调 final Messenger callback = msg.replyTo; try { // 回调 callback.send(Message.obtain(null, 0)); } catch (RemoteException e) { // TODO

How to receive an image in a Facebook Messenger bot

给你一囗甜甜゛ 提交于 2019-12-07 01:47:09
问题 How can I receive an attachment in form of an image through the Facebook Messenger API? Their documentation only provides instructions on how to receive text-based messages. 回答1: I am not sure what language you are using to code your bot but since you are referring to the facebook documents where most of the messenger code snippets are in node.js Here's something for you to try, let me know if this helps. app.post('/webhook/', function (req, res) { //Getting the mesagess var messaging_events

Android 使用Messenger跨进程通信框架

柔情痞子 提交于 2019-12-06 12:30:20
一.通过Binder绑定形式的通信 上一篇说道Binder机制的通信框架,也说过Messenger的底层实现自AIDL,因此对于跨进程通信中,Messenger是一种比较高级的框架,可以说对于一个app开发者来说重要性不言而喻 服务端模型 public class BackgroundService extends Service { private Messenger mMessenger = null;//监听数据 private Messenger replyMessenger = null //响应数据 @Override public IBinder onBind(Intent intent) { if(mMessenger==null) { mMessenger = new Messenger(new ServerHandler()); } return mMessenger.getBinder(); } @Override public boolean onUnbind(Intent intent) { return super.onUnbind(intent); } //注意,将ServerHandler静态化,以防止内存泄露 public static class ServerHandler extends Handler { @Override public

FB Messenger Message Template

自作多情 提交于 2019-12-06 11:50:14
问题 How can I achieve this template in fb messenger platform? It seems that the color of the shirt and the price are both subtitles of the message but there can only be 1 subtitle in a message. So how can achieve where there are two subtitles? This is my current message tempalate "message":{ "attachment":{ "type":"template", "payload":{ "template_type":"generic", "elements":[ { "title":"Classic T-Shirt", "image_url":"http://petersapparel.parseapp.com/img/item100-thumb.png", "subtitle":"Medium

Messenger方式实现进程间通讯

天大地大妈咪最大 提交于 2019-12-06 08:05:33
简介 进程间通讯相信大家的比较熟悉,而广为人知的通讯有两种,一种就是通过AIDL文件编写通讯接口,另一种就是今天我要说的Messenger。其实Messenger就是基于AIDL实现的,不懂的自行百度。 作用 当一个app的功能越来越多,越来越复杂,那么是不是需要更多资源和时间去处理呢?那是肯定的,但一个进程能获得的资源是有限的,而且这个进程既要负责ui绘制又要进行复杂运算,想想就知道继续这样下去你的app只会越来越卡,只显然不符合用户的期望。所以多进程概念应运而生,将ui绘制和逻辑运算放到不同进程里进行,那么影响ui卡顿的问题就只有控件的性能这个因素了。而且逻辑运算报错导致崩溃不再影响ui,ui正常使用,提高应用整体稳定性。 实现 开启一个远程Services充当本地服务器,用于处理客户端发送的计算请求(这里的客户端指代ui)。Services的配置如下图所示,使用process属性定义其为一个远程服务。 Activity与Services交互方式就两种,stratSerices和bindServices,这里我采用的是bindServices方式,传入的上下文为Application,这样使得这个服务的生命周期与app一致。 具体的连接逻辑如下图所示: connect()方法就是调用bindServices方法和开启一个线程经行轮询(检查当前是否有客户端请求)

When and where to unregister messenger with mvvmlight

六眼飞鱼酱① 提交于 2019-12-06 06:23:06
问题 I build a project with mvvmlight. Using Messenger send message between VMs or VM and View. Now, I wonder that when and where to unregister messenger. Could u help me? Edited: This is my scene: There are a MainWindow and a ChildWindow, the ChildWindow (include a ContentControl consist of one of two different UserControl), change the ContenControl via a SwitchButton in ChildWindow. Every window or UserControl corresponding to a ViewModel. MainViewModel sends a message to MainWindow to open the

Facebook Messenger bot object structure for java

不羁的心 提交于 2019-12-06 03:57:35
问题 Has anyone created an open source project that exposes the facebook messenger bot API in java? (or another language I could convert?) Essentially an object hierarchy for the stack found in: https://developers.facebook.com/docs/messenger-platform/send-api-reference I'd rather not just use JsonObjects, etc. nor Maps to extract the incoming JSON chat messages or to build the outgoing structured chat replies. If an open source project for this exists -- I have not found it. 回答1: Take a look at

Messenger Bot Fails to Respond

徘徊边缘 提交于 2019-12-06 03:44:21
My bot has been approved and is available publicly (see image) , but it does not respond to anyone besides the developer. I have it hosted on Heroku. I have tried to debug it with a ton of console logs, and I have realized that it doesn't log the "Enter App.Post" (see below) when any one other than the developer sends it a message. Has anybody else experienced this behavior? /// Facebook verification app.get('/webhook/', function (req, res) { if (req.query['hub.verify_token'] === '***************') { res.send(req.query['hub.challenge']) } res.send('Error, wrong token') }) /// Star up the

Facebook Messenger API - Persistent Menu not working on mobile

淺唱寂寞╮ 提交于 2019-12-06 02:57:45
问题 I am making a php curl call to the API endpoint to set up a persistent menu based on the documentation. Here is the code: $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'https://graph.facebook.com/v2.6/me/thread_settings?access_token='.FB_ACCESS_TOKEN); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $postbody); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_SSL

Facebook Messenger Bot - How to disable bot and allow human to chat

大城市里の小女人 提交于 2019-12-05 16:31:44
问题 so this is something I've been trying to think through for about 16 hours. I am coding with PHP / CuRl / etc - the bot works and everything is fine. My current issue is figuring out how to disable the bot and allow a human to begin chatting with the customer/sender. Has anyone successfully, created a route for this ? I mean it's pretty hard from what I see, you'd have to disable etc etc. A lot of effort for my clients. Thanks for any input. 回答1: Facebook has rolled out a "Handover Protocol"