{"size": 1355, "ext": "js", "max_stars_repo_path": "examples/conversations/purchase_conversion.js", "max_stars_repo_name": "zaaferani67/bale-bot-nodejs", "max_stars_repo_stars_event_min_datetime": "2018-07-08T12:18:09.000Z", "max_stars_repo_stars_event_max_datetime": "2018-12-19T05:33:48.000Z", "max_issues_repo_path": "examples/conversations/purchase_conversion.js", "max_issues_repo_name": "zaaferani67/bale-bot-nodejs", "max_issues_repo_issues_event_min_datetime": "2018-07-17T09:17:39.000Z", "max_issues_repo_issues_event_max_datetime": "2019-08-04T16:41:14.000Z", "max_forks_repo_path": "examples/conversations/purchase_conversion.js", "max_forks_repo_name": "zaaferani67/bale-bot-nodejs", "max_forks_repo_forks_event_min_datetime": "2018-07-07T08:28:49.000Z", "max_forks_repo_forks_event_max_datetime": "2019-02-13T19:28:40.000Z"}
{"max_stars_count": 9, "max_issues_count": 11, "max_forks_count": 6, "avg_line_length": 35.6578947368, "max_line_length": 163, "alphanum_fraction": 0.6531365314}
const Platform = require("../../index");
const Bot = Platform.BaleBot;
const Conversation = Platform.Conversation;
const PurchaseMessage = Platform.PurchaseMessage;
const PhotoMessage = Platform.PhotoMessage;
const MoneyRequestType=Platform.MoneyRequestType;
let conv = new Conversation();

let bot = new Bot("Bot Token");


conv.startsWith(["/start"]).then((message, session, responder) => {
    //STATE 0
    responder.reply("Send me a photo");
    //Go to the next state
    session.next();
}).then((message, session, responder) => {
    //STATE 1
    if (message instanceof PhotoMessage) {
        let purchaseMessage = new PurchaseMessage(message, '6037991067471130', '10000', new MoneyRequestType().normal);
        bot.send(purchaseMessage, responder.peer).then((res) => {
            console.log(res)
        }).catch((err) => {
            console.log(err)
        });
        session.reset();
    } else {
        responder.reply("Ops... ,Send me a photo");
        // Don't call session.next() to remain in the current state.
    }
});

// Within a conversation (when it's active and in some state other than first state) the user can finish it by sending a message. In this case: /end, /stop, or /by
conv.cancelsWith(["/end", "/stop", "/bye"], (message, session, responder) => {
    responder.reply("OK. bye!");
});

bot.setConversation(conv);