The Bot framework works fine alone... however, when using Facebook Messenger, it drives me crazy😩!
There are message types like 'quick choices' and 'hero cards' which render differently on various clients. I successfully have these working (after some messing about)... see 'Rules for FB messages to render' below.
However, when I'd attempt to apply them in the real-use case I had planned then they would fail. Today, I took some time today to try to understand the root cause.
I've come to the conclusion that FB won't accept the more advanced message types when sent from a 'Continued Conversation', that is a conversation that has ended for a while. When a server-side event triggers such a case then the best my Bot can do is send a simple text message to the user. Any more complex interaction than that seem like it will be left to the interactions that follow from the user.
Rules for FB messages to render:
1/ Bot must be published (not on local host)
2/ Use the FacebookAdapter
3/ Facebook Channel must be configured in Azure.
The above allows bot framework to transform the markup into the format needed for messenger.
The bot has been working in Facebook messenger for a day or two (dev mode only) but I could not receive the all important checkin messages the bot was trying to send me.
The error related to permissions and Auth... I started to worry if FB messenger would support the interactions the bot needed. Trawling through the facebook documentation just made me more worried, it seemed to confirm my suspicions about the one-time message requirement.
After working through my code line by line again I found that I had been attempting to post the message back to Messenger on an overridden instance of the adapter (non-facebook aware) that at a low level was not sending the auth requirement to FB 🤦
All good! looks like I'll be able to check-in with users each day or as they reach a goal date OK.
After a week or so of coding on the bot I am familiar with the interactions. Now with data persistence I am need to get into some heavier implementation with reminder push notifications etc. The codebase was getting a bit messy from experiments and learning how some of this stuff all holds together.
Time for a refactor 🤜
I needed to split out my code into clear repositories for data, services for the business logic. Bot controllers and data models that face the user.
Done! much happier coding now.
Conversation states in Bots are like a blob of json that represents some dynamic objects you and the frameworks have created throughout the conversation.
I dived into researching a few different ways of persisting the database. The one I found I was most comfortable with was a good'ol relational database. Later I'll add a dashboard and other features that will need this capability so it made more sense than a noSQL store. Nice thing about SQL is that the whole state can be stored in single columns with just the keys around it.
The Bot Framework community has developed a library that made this easier to setup and implement.
Building a conversational bot is a bit like your first day coding a console app. The first few things you write are the typical 'hello world' and next the 'echo bot' that will repeat anything you enter.
Building more complex user experiences beyond that is a bit of a learning curve! There is the whole concept of managing who's turn it is in the conversation. Handling state in a sequence of questions to complete a 'dialog'.
Feeling reasonably comfortable now.
This is a side project so I am looking to do everything as quick as possible. Created an alias and redirect to my existing site for the new domain DayNinja.app. Initially I had an issue in the redirect would show a security warning. But support @ accu hosting were great and added domain to the cert for free (thanks!).
As a founder and agency owner time is my most precious resource.
I've struggled with all sorts of products to keep me accountable and on track. I building a bot that will help you apply the method that works for me.